- in a variety of hardcopy formats (ps, pdf, svg, png, etc)
- and interactive environments (gtk, tk, qt, wx, html5, etc)
- across platforms (linux&unix, mac os X, windows).
x = randn(10000) hist(x, 100)
Read The Fine Manual
The matplotlib code is conceptually divided into three parts:
def draw(self, renderer): 'Draw the :class:`Patch` to the given *renderer*.' if not self.get_visible(): return renderer.open_group('patch', self.get_gid()) gc = renderer.new_gc() gc.set_foreground(self._edgecolor, isRGB=True) lw = self._linewidth if self._edgecolor[3] == 0: lw = 0 gc.set_linewidth(lw) gc.set_linestyle(self._linestyle) # .... path = self.get_path() transform = self.get_transform() tpath = transform.transform_path_non_affine(path) affine = transform.get_affine() # may use path_effects .. renderer.draw_path(gc, tpath, affine, rgbFace) gc.restore() renderer.close_group('patch')
MATLAB-like environments
See http://matplotlib.sourceforge.net/users/gridspec.html
import matplotlib.gridspec as gridspec gs = gridspec.GridSpec(3, 3) ax1 = plt.subplot(gs[0, :]) ax2 = plt.subplot(gs[1,:-1]) ax3 = plt.subplot(gs[1:, -1]) ax4 = plt.subplot(gs[-1,0]) ax5 = plt.subplot(gs[-1,-2])
from matplotlib.gridspec import GridSpec, GridSpecFromSubplotSpec gs = GridSpec(1,2) ax1 = plt.subplot(gs[0]) gs1 = GridSpecFromSubplotSpec(3, 3, subplot_spec=gs[1]) ax2 = plt.subplot(gs1[0])
fig, ax_list = subplots(2,2) arr = np.arange(100).reshape((10,10)) for ax in ax_list.flat: ax.imshow(arr) plt.subplots_adjust(wspace=0.02, hspace=0.02)
http://matplotlib.sourceforge.net/mpl_toolkits/axes_grid/index.html#toolkit-axesgrid-index
from mpl_toolkits.axes_grid1 import ImageGrid fig = plt.figure(1) grid = ImageGrid(fig, 111, # similar to subplot(111) nrows_ncols = (2, 2), # creates 2x2 grid of axes axes_pad=0.1, # pad between axes in inch. ) for ax in grid: # sequence-like interface for axes in the grid ax.imshow(arr)
plt.plot([0, 1], [0, 1], "-") plt.tight_layout() plt.gca().set_aspect(1) plt.tight_layout() plt.savefig("a.png", bbox_inches="tight")
tex_string = r'$\displaystyle \mathcal{F} = \int f\left( \phi, c \right)' \ r'dV$, $\displaystyle\frac{ \partial \phi } { \partial t }' \ r'= -M_{ \phi } \frac{ \delta \mathcal{F} }' \ r'{ \delta \phi }$' bbox_props = dict(boxstyle="round", fc="0.9", ec="0.5", alpha=0.9) plt.text(0.2, 0.15, tex_string, {'color' : 'r', 'fontsize' : 20}, bbox=bbox_props)
http://matplotlib.sourceforge.net/users/annotations_guide.html
plt.plot([0.2], [0.2], "o") ann = plt.annotate("Test", xy=(0.2, 0.2), xycoords='data', xytext=(50, 50), textcoords='offset points', arrowprops=dict(arrowstyle="->", shrinkB=10, connectionstyle="angle3"), size=30 )
annoation are dragable.
ann.dragable()
from matplotlib.patheffects import withStroke imshow([[1,2],[2,3]], interpolation="bilinear") txt = annotate("test", (1., 1.), (0., 0), arrowprops=dict(arrowstyle="->", connectionstyle="angle3", lw=2), size=20, ha="center") txt.set_path_effects([withStroke(linewidth=3, foreground="w")]) txt.arrow_patch.set_path_effects([withStroke(linewidth=5, foreground="w")])
from mpl_toolkits.axes_grid1.inset_locator import inset_axes, zoomed_inset_axes from mpl_toolkits.axes_grid1.anchored_artists import AnchoredSizeBar ax = fig.add_subplot(111) ax.set_aspect(1.) axins = inset_axes(ax, width="30%", # width = 30% of parent_bbox height=1., # height : 1 inch loc=3) axins.axis[:].toggle(ticklabels=False)
axins = zoomed_inset_axes(ax, 3, loc=1) # zoom = 6
Table of Contents | t |
---|---|
Exposé | ESC |
Full screen slides | e |
Presenter View | p |
Source Files | s |
Slide Numbers | n |
Toggle screen blanking | b |
Show/hide slide context | c |
Notes | 2 |
Help | h |