Introducing Tim Sheerman-Chase This work is licensed under a Creative Commons Attribution 3.0 Unported License 28 th Sept 2011
Overview matplotlib is a high quality plotting tool Depends on: Can be used via command line, by a script or by a GUI program Alternatives: gnuplot or matlab Easy to use, free software, customisable Project web page:
How To Use matplotlib pylab is a quick way to start python with: numpy (low level maths) scipy (high level maths) matplotlib (figure plotting) Everything in one namespace (yikes!) Quick start, plot 100 histogram of samples of a normal distribution ipython -pylab x = randn(10000) hist(x,100) Start pylab from linux shell Use numpy to get samples Plot histogram
Histogram Result matplotlib can save vector formatted graphs to SVG or PDF
Simple Line Plot with Latex Labels plot([1,3,2,4]) title('Time dependency of Foo') xlabel('Time (sec)') ylabel(r'Observed Value $Z^{a}_{b}$') grid(True)
Scatter Plot with Legend x = arange(0.,2.*math.pi,0.2) print "Shape of x",x.shape plot(x, sin(x), 'o', label="sin(x)") plot(x, cos(x), 'x', label="cos(x)") legend() savefig("plot.svg")
Annotations annotate('Intercept', xy=(math.pi,0), xytext=(3.5,0.5), arrowprops=dict(facecolor='black'))
Final Word View the matplotlib gallery for inspiration Any questions?