summaryrefslogtreecommitdiff
path: root/day1/cheatsheet1.tex
blob: 42b46b171cc597c2961f8990e7dba6eddf05e777 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
\documentclass[12pt]{article}


\title{Interactive Plotting}
\author{FOSSEE}
\usepackage{listings}
\lstset{language=Python,
    basicstyle=\ttfamily,
commentstyle=\itshape\bfseries
}
\newcommand{\typ}[1]{\lstinline{#1}}
\usepackage[english]{babel}
\usepackage[latin1]{inputenc}
\usepackage{times}
\usepackage[T1]{fontenc}
\usepackage{ae,aecompl}
\usepackage{mathpazo,courier,euler}
\usepackage[scaled=.95]{helvet}

\begin{document}
\date{}
\vspace{-1in}
\begin{center}
\LARGE{Interactive Plotting}\\
\large{FOSSEE}
\end{center}
\section{Starting up...}

\begin{lstlisting}
  $ ipython -pylab  
\end{lstlisting}
Exiting 
\begin{lstlisting}     
In [2]: (Ctrl-D)^D
Do you really want to exit ([y]/n)? y
\end{lstlisting} %$

\section{Plotting}

\subsection{Label}
Pylab accepts TeX equation expressions in any text expression. To get something like:\\
$\sigma_i=15$ \\
on title of figure use: 
\begin{lstlisting}
  title('$\sigma_i=15$')
\end{lstlisting}  
Same way one can have TeX expression on xlabel, ylabel etc.

\subsection{legends}
Apart from using \kwrd{loc='center'} for positioning the legend, one can also mention explicit co-ordinates for placement. 
\begin{lstlisting}
In []: legend(['sin(2y)'], loc=(.8,.1)) 
\end{lstlisting}
\typ{loc = 0, 1} (left top position of graph)\\
\typ{loc = 0.5, 0.5} (center of graph).

%\subsection{Multiple figures}

\subsection{Saving figures}
One can save figure in any of these formats: png, pdf, ps, eps and svg.
  \begin{lstlisting}
In [1]: x = linspace(0, 2*pi, 50)
In [2]: plot(x, sin(x))
In [3]: xlabel('x')
In [4]: ylabel('sin(x)')
In [5]: title('Sinusoids')
In [6]: legend(['sin(y)'])
In [7]: legend(['sin(2y)'], loc = 'center')
# loc = 'upper right', 'upper left', 'lower left, 'lower right', 'center left',
#      'center right', 'lower center', 'upper center', 'best', 'right', 'center'

In [8]: legend(['sin(2y)'], loc = (.8, .1))

In [9]: savefig('sin.png')   # Save figure
In [10]: close()             # Closes the figure

In [11]: clf()               # Clears the Plot area

In [12]: plot(y, sin(y), 'g')
# Colors can be: 'b', 'g', 'r', 'c', 'm', 'y', 'k', 'w'

In [13]: plot(y, cos(y), 'r', linewidth=2)

In [14]: legend(['x', '-x'])
In [15]: annotate('origin', xy=(0, 0))

In [16]: xmin, xman = xlim()           # Without arguments gets
In [17]: ymin, ymax = ylim()           # values

In [18]: xlim(0, 2 * pi)               # With values, sets the
In [19]: ylim(ymin - 0.2, ymax + 0.2)  # specified values
  \end{lstlisting}

\section{Saving and running scripts}
\begin{itemize}
  \item \typ{\%hist}
  \item \typ{\%save four\_plot.py 16 18-27}
  \item \typ{\%run -i four\_plot.py}
\end{itemize}

\end{document}