Matplotlib
Jump to navigation
Jump to search
Contents
matplotlib.pyplot
- from matplotlib import pyplot
matplotlib.pyplot.figure
member functions
ax = matplotlib.pyplot.figure.add_subplot( ... )
- returns instance of matplotlib.axes.AxesSubplot
plot([1,2,3], [1,2,3], 'go-', label='line 1', linewidth=2) plot([1,2,3], [1,4,9], 'rs', label='line 2') axis([0, 4, 0, 10]) legend()
import matplotlib.pyplot as plt fig = plt.figure() ax = fig.add_subplot(111) ax.imshow(np.rot90(Z), cmap=plt.cm.gist_earth_r, extent=[xmin, xmax, ymin, ymax]) ax.plot(m1, m2, 'k.', markersize=2) ax.set_xlim([xmin, xmax]) ax.set_ylim([ymin, ymax]) plt.show()
matplotlib.axes
matplotlib.axes.AxesSubplot
- call ax.plot and ax.hist(...) ... the ax instance is what you garnish
- ax.set_xlabel('Smarts')
- ax.set_ylabel('Probability')
- ax.set_title(r'$\mathrm{Histogram\ of\ IQ:}\ \mu=100,\ \sigma=15$')
- ax.set_xlim(40, 160)
- ax.set_ylim(0, 0.03)
- ax.grid(True)
matplotlib artist
- Three layers to the matplotlib API in
matplotlib.backend_bases
FigureCanvas
= the area onto which the figure is drawnRenderer
= the object which knows how to draw on the FigureCanvasArtist
= the object that knows how to use a renderer to paint onto the canvas
- FigureCanvas and Renderer abstract away the lowlevel calls to toolkits (PostScript, PDF Gtk+, or wxPython)
- Artist handles high level constructs
- 2 types of artists
- primitives: Line2D, Rectangle, Text, AxesImage
- containers: Axis, Axes, Figure
- Create Figure instance
- Use figure to create one or more axes or subplot instances
- Use Axes instance helper methods to create the primitives
scipy.stats
scipy.stats.gaussian_kde
numpy.mgrid
- Specify a start, stop and the number of steps in between (expressed in complex notation),and get an array with all the values in between
np.mgrid[1:100:100j]
-- yields a list of numbers from 1 to 100X, Y = np.mgrid[xmin:xmax:100j, ymin:ymax:100j]
numpy.ravel
- return a flattened array, i.e., turns a matrix into an array.
- can also specify ravelling order, row-major, column-major or otherwise