day1/cheatsheet1.tex
changeset 317 0eca6c542fce
parent 308 d93be08d69f8
child 325 0cde91487637
equal deleted inserted replaced
316:6108f2007151 317:0eca6c542fce
    35 In [2]: (Ctrl-D)^D
    35 In [2]: (Ctrl-D)^D
    36 Do you really want to exit ([y]/n)? y
    36 Do you really want to exit ([y]/n)? y
    37 \end{lstlisting} %$
    37 \end{lstlisting} %$
    38 
    38 
    39 \section{Plotting}
    39 \section{Plotting}
       
    40 \subsection{linspace}
       
    41 \typ{In []: x = linspace(start, stop, num)}\\
       
    42 \typ{linspace} returns array of length \typ{num}, for which \typ{x[0] = start} and \typ{x[num-1] = stop} \\
       
    43 \emph{Please note indices of array starts from zero(0)}
    40 
    44 
    41 \subsection{Label}
    45 \subsection{plot}
       
    46 \typ{In []: plot(X, Y)}\\
       
    47 For given arrays of equal length(above case X and Y), \typ{plot} plots the correspoding *x* and *y* pairs taken from X and Y.
       
    48 
       
    49 \subsection{Colors of plots}
       
    50 \typ{In []: plot(y, sin(y), 'g')}\\
       
    51 Plots graph with green color. Other options available are:
       
    52 \begin{lstlisting}
       
    53   'r' ---> Red
       
    54   'b' ---> Blue
       
    55   'r' ---> Red 
       
    56   'c' ---> Cyan 
       
    57   'm' ---> Magenta
       
    58   'y' ---> Yellow
       
    59   'k' ---> Black 
       
    60   'w' ---> White
       
    61 \end{lstlisting}
       
    62 One can also set the line width of plot using optional argument \typ{linewidth}. For example:\\
       
    63 \typ{In []: plot(x, cos(x), 'r', linewidth=2)}\\
       
    64 Plots the line with linewidth = 2
       
    65 \subsection{label and title}
       
    66 \typ{In []: xlabel('Length') #sets *x* axis label to Length}\\ 
       
    67 \typ{In []: ylabel('Time') #sets *y* axis label to Time.}\\
       
    68 \typ{In []: title('Sinusoids') #sets title of plot}\\
       
    69 \\
       
    70 \textbf{Additionally}\\
    42 Pylab accepts TeX equation expressions in any text expression. To get something like:\\
    71 Pylab accepts TeX equation expressions in any text expression. To get something like:\\
    43 $\sigma_i=15$ \\
    72 $\sigma_i=15$ \\
    44 on title of figure use: 
    73 on title of figure use: 
    45 \begin{lstlisting}
    74 \begin{lstlisting}
    46   title('$\sigma_i=15$')
    75 In []: title('$\sigma_i=15$')
    47 \end{lstlisting}  
    76 \end{lstlisting}  
    48 Same way one can have TeX expression on xlabel, ylabel etc.
    77 Same way one can have TeX expression on xlabel, ylabel etc.
    49 
    78 
    50 \subsection{legends}
    79 \subsection{legends}
       
    80 \typ{In []: legend('sin(x)',loc=center)} \\
       
    81 Placec a legend on the current plot at location *loc*.\\
    51 Apart from \kwrd{center}, some other \kwrd{loc} which can be specified are:
    82 Apart from \kwrd{center}, some other \kwrd{loc} which can be specified are:
    52 \begin{lstlisting}
    83 \begin{lstlisting}
       
    84 'best'
       
    85 'right'
    53 'upper right'
    86 'upper right'
    54 'upper left'      
    87 'upper left'      
    55 'lower left'      
    88 'lower left'      
    56 'lower right'     
    89 'lower right'     
    57 'center left'     
    90 'center left'     
    62 \newpage
    95 \newpage
    63 One can also mention explicit co-ordinates for placement of legend. 
    96 One can also mention explicit co-ordinates for placement of legend. 
    64 \begin{lstlisting}
    97 \begin{lstlisting}
    65 In []: legend(['sin(2y)'], loc=(.8,.1)) 
    98 In []: legend(['sin(2y)'], loc=(.8,.1)) 
    66 \end{lstlisting}
    99 \end{lstlisting}
    67 \typ{loc = 0, 1} (left top position of graph)\\
   100 \typ{loc = 0, 1} (top left position of graph)\\
    68 \typ{loc = 0.5, 0.5} (center of graph).
   101 \typ{loc = 0.5, 0.5} (center of graph).
    69 
   102 
       
   103 \subsection{Annotate}
       
   104 \typ{In []: annotate('local max', xy=(1.5, 1))}\\
       
   105 Annotates current plot with text, 'local max', at position specified to \typ{xy}.
       
   106 
    70 \subsection{Saving figures}
   107 \subsection{Saving figures}
    71 One can save figure in any of these formats: png, pdf, ps, eps and svg.
   108 \typ{In []: savefig('sinusoids.png')}\\
       
   109 Saves the current figure with file name 'sinusoids.png' in current working directory. One can save figure in any of these formats: png, pdf, ps, eps and svg.
    72 
   110 
    73 \subsection{Colors of plots}
   111 \subsection{Miscellaneous}
    74 \typ{In []: plot(y, sin(y), 'g')}\\
   112 \typ{In []: clf() #Clears the current plot area}\\
    75 Plots graph with green color. Other options available are:
   113 \typ{In []: close() #Closes the figure}
    76 \begin{lstlisting}
       
    77   'r' ---> Red
       
    78   'b' ---> Blue
       
    79   'r' ---> Red 
       
    80   'c' ---> Cyan 
       
    81   'm' ---> Magenta
       
    82   'y' ---> Yellow
       
    83   'k' ---> Black 
       
    84   'w' ---> White
       
    85 \end{lstlisting}
       
    86 
       
    87 \section{Saving and running scripts}
   114 \section{Saving and running scripts}
    88 \begin{itemize}
   115 \begin{itemize}
    89   \item \typ{\%hist}\\
   116   \item \typ{\%hist}\\
    90   It returns the logs of all commands(including mistakes) used in IPython interpreter.
   117   It returns the logs of all commands(including mistakes) used in IPython interpreter.
    91   \item \typ{\%hist -n}\\
   118   \item \typ{\%hist -n}\\
   103 In []: plot(x, cos(x), 'r', linewidth=2)
   130 In []: plot(x, cos(x), 'r', linewidth=2)
   104 In []: xlabel('x')
   131 In []: xlabel('x')
   105 In []: title('Sinusoidal Waves')
   132 In []: title('Sinusoidal Waves')
   106 In []: legend(['sin(x)', 'cos(x)'])
   133 In []: legend(['sin(x)', 'cos(x)'])
   107 In []: annotate('origin', xy=(0, 0))
   134 In []: annotate('origin', xy=(0, 0))
   108 In []: xmin, xman = xlim()           # Without arguments gets
   135 In []: xmin, xman = xlim()  # returns current X axis limits.
   109 In []: ymin, ymax = ylim()           # values
   136 In []: ymin, ymax = ylim()
   110 
   137 In []: xlim(0, 2 * pi) # sets the X axis limits to passed values
   111 In []: xlim(0, 2 * pi)               # With values, sets the
   138 In []: ylim(ymin - 0.2, ymax + 0.2) 
   112 In []: ylim(ymin - 0.2, ymax + 0.2)  # specified values
       
   113 
   139 
   114 In []: savefig('sin.png')   # Save figure
   140 In []: savefig('sin.png')   # Save figure
   115 In []: close()              # Closes the figure
   141 In []: close()              
   116   \end{lstlisting}
   142   \end{lstlisting}
   117 
   143 
   118 \section{References}
   144 \section{References}
   119 \begin{itemize}
   145 \begin{itemize}
   120   \item For documentation on IPython refer: \\ \url{http://ipython.scipy.org/moin/Documentation}
   146   \item For documentation on IPython refer: \\ \url{http://ipython.scipy.org/moin/Documentation}