45 title('$\sigma_i=15$') |
46 title('$\sigma_i=15$') |
46 \end{lstlisting} |
47 \end{lstlisting} |
47 Same way one can have TeX expression on xlabel, ylabel etc. |
48 Same way one can have TeX expression on xlabel, ylabel etc. |
48 |
49 |
49 \subsection{legends} |
50 \subsection{legends} |
50 Apart from using \kwrd{loc='center'} for positioning the legend, one can also mention explicit co-ordinates for placement. |
51 Apart from \kwrd{center}, some other \kwrd{loc} which can be specified are: |
|
52 \begin{lstlisting} |
|
53 'upper right' |
|
54 'upper left' |
|
55 'lower left' |
|
56 'lower right' |
|
57 'center left' |
|
58 'center right' |
|
59 'lower center' |
|
60 'upper center' |
|
61 \end{lstlisting} |
|
62 \newpage |
|
63 One can also mention explicit co-ordinates for placement of legend. |
51 \begin{lstlisting} |
64 \begin{lstlisting} |
52 In []: legend(['sin(2y)'], loc=(.8,.1)) |
65 In []: legend(['sin(2y)'], loc=(.8,.1)) |
53 \end{lstlisting} |
66 \end{lstlisting} |
54 \typ{loc = 0, 1} (left top position of graph)\\ |
67 \typ{loc = 0, 1} (left top position of graph)\\ |
55 \typ{loc = 0.5, 0.5} (center of graph). |
68 \typ{loc = 0.5, 0.5} (center of graph). |
56 |
69 |
57 %\subsection{Multiple figures} |
|
58 |
|
59 \subsection{Saving figures} |
70 \subsection{Saving figures} |
60 One can save figure in any of these formats: png, pdf, ps, eps and svg. |
71 One can save figure in any of these formats: png, pdf, ps, eps and svg. |
61 \begin{lstlisting} |
|
62 In [1]: x = linspace(0, 2*pi, 50) |
|
63 In [2]: plot(x, sin(x)) |
|
64 In [3]: xlabel('x') |
|
65 In [4]: ylabel('sin(x)') |
|
66 In [5]: title('Sinusoids') |
|
67 In [6]: legend(['sin(y)']) |
|
68 In [7]: legend(['sin(2y)'], loc = 'center') |
|
69 # loc = 'upper right', 'upper left', 'lower left, 'lower right', 'center left', |
|
70 # 'center right', 'lower center', 'upper center', 'best', 'right', 'center' |
|
71 |
72 |
72 In [8]: legend(['sin(2y)'], loc = (.8, .1)) |
73 \subsection{Colors of plots} |
73 |
74 \typ{In []: plot(y, sin(y), 'g')}\\ |
74 In [9]: savefig('sin.png') # Save figure |
75 Plots graph with green color. Other options available are: |
75 In [10]: close() # Closes the figure |
76 \begin{lstlisting} |
76 |
77 'r' ---> Red |
77 In [11]: clf() # Clears the Plot area |
78 'b' ---> Blue |
78 |
79 'r' ---> Red |
79 In [12]: plot(y, sin(y), 'g') |
80 'c' ---> Cyan |
80 # Colors can be: 'b', 'g', 'r', 'c', 'm', 'y', 'k', 'w' |
81 'm' ---> Magenta |
81 |
82 'y' ---> Yellow |
82 In [13]: plot(y, cos(y), 'r', linewidth=2) |
83 'k' ---> Black |
83 |
84 'w' ---> White |
84 In [14]: legend(['x', '-x']) |
85 \end{lstlisting} |
85 In [15]: annotate('origin', xy=(0, 0)) |
|
86 |
|
87 In [16]: xmin, xman = xlim() # Without arguments gets |
|
88 In [17]: ymin, ymax = ylim() # values |
|
89 |
|
90 In [18]: xlim(0, 2 * pi) # With values, sets the |
|
91 In [19]: ylim(ymin - 0.2, ymax + 0.2) # specified values |
|
92 \end{lstlisting} |
|
93 |
86 |
94 \section{Saving and running scripts} |
87 \section{Saving and running scripts} |
95 \begin{itemize} |
88 \begin{itemize} |
96 \item \typ{\%hist} |
89 \item \typ{\%hist}\\ |
97 \item \typ{\%save four\_plot.py 16 18-27} |
90 It returns the logs of all commands(including mistakes) used in IPython interpreter. |
98 \item \typ{\%run -i four\_plot.py} |
91 \item \typ{\%hist -n}\\ |
|
92 It disables the line number representation of logs. |
|
93 \item \typ{\%save four\_plot.py 16 18-27}\\ |
|
94 For creating a script named four\_plot which includes line 16 and line 18 to 27 of logs. |
|
95 \item \typ{\%run -i four\_plot.py}\\ |
|
96 Running the python script inside IPython interpreter. |
99 \end{itemize} |
97 \end{itemize} |
100 |
98 |
|
99 \section{Example} |
|
100 \begin{lstlisting} |
|
101 In []: x = linspace(0, 2*pi, 50) |
|
102 In []: plot(x, sin(x), 'g') |
|
103 In []: plot(x, cos(x), 'r', linewidth=2) |
|
104 In []: xlabel('x') |
|
105 In []: title('Sinusoidal Waves') |
|
106 In []: legend(['sin(x)', 'cos(x)']) |
|
107 In []: annotate('origin', xy=(0, 0)) |
|
108 In []: xmin, xman = xlim() # Without arguments gets |
|
109 In []: ymin, ymax = ylim() # values |
|
110 |
|
111 In []: xlim(0, 2 * pi) # With values, sets the |
|
112 In []: ylim(ymin - 0.2, ymax + 0.2) # specified values |
|
113 |
|
114 In []: savefig('sin.png') # Save figure |
|
115 In []: close() # Closes the figure |
|
116 \end{lstlisting} |
|
117 |
|
118 \section{References} |
|
119 \begin{itemize} |
|
120 \item For documentation on IPython refer: \\ \url{http://ipython.scipy.org/moin/Documentation} |
|
121 \item Plotting(matplotlib) related documentation are available at:\\ \url{http://matplotlib.sourceforge.net/contents.html} |
|
122 \item Explore examples and plots based on matplotlib at \\ \url{http://matplotlib.sourceforge.net/examples/index.html} |
|
123 \end{itemize} |
101 \end{document} |
124 \end{document} |
102 |
125 |