Movatterモバイル変換


[0]ホーム

URL:


You are reading an old version of the documentation (v2.0.0). For the latest version seehttps://matplotlib.org/stable/
matplotlib

Navigation


Travis-CI:

Related Topics

This Page

Quick search

axes_grid example code: demo_axes_grid.py

(Source code,png,pdf)

../../_images/demo_axes_grid.png
importmatplotlib.pyplotaspltfrommpl_toolkits.axes_grid1importAxesGriddefget_demo_image():importnumpyasnpfrommatplotlib.cbookimportget_sample_dataf=get_sample_data("axes_grid/bivariate_normal.npy",asfileobj=False)z=np.load(f)# z is a numpy array of 15x15returnz,(-3,4,-4,3)defdemo_simple_grid(fig):"""    A grid of 2x2 images with 0.05 inch pad between images and only    the lower-left axes is labeled.    """grid=AxesGrid(fig,141,# similar to subplot(141)nrows_ncols=(2,2),axes_pad=0.05,label_mode="1",)Z,extent=get_demo_image()foriinrange(4):im=grid[i].imshow(Z,extent=extent,interpolation="nearest")# This only affects axes in first column and second row as share_all =# False.grid.axes_llc.set_xticks([-2,0,2])grid.axes_llc.set_yticks([-2,0,2])defdemo_grid_with_single_cbar(fig):"""    A grid of 2x2 images with a single colorbar    """grid=AxesGrid(fig,142,# similar to subplot(142)nrows_ncols=(2,2),axes_pad=0.0,share_all=True,label_mode="L",cbar_location="top",cbar_mode="single",)Z,extent=get_demo_image()foriinrange(4):im=grid[i].imshow(Z,extent=extent,interpolation="nearest")#plt.colorbar(im, cax = grid.cbar_axes[0])grid.cbar_axes[0].colorbar(im)forcaxingrid.cbar_axes:cax.toggle_label(False)# This affects all axes as share_all = True.grid.axes_llc.set_xticks([-2,0,2])grid.axes_llc.set_yticks([-2,0,2])defdemo_grid_with_each_cbar(fig):"""    A grid of 2x2 images. Each image has its own colorbar.    """grid=AxesGrid(fig,143,# similar to subplot(143)nrows_ncols=(2,2),axes_pad=0.1,label_mode="1",share_all=True,cbar_location="top",cbar_mode="each",cbar_size="7%",cbar_pad="2%",)Z,extent=get_demo_image()foriinrange(4):im=grid[i].imshow(Z,extent=extent,interpolation="nearest")grid.cbar_axes[i].colorbar(im)forcaxingrid.cbar_axes:cax.toggle_label(False)# This affects all axes because we set share_all = True.grid.axes_llc.set_xticks([-2,0,2])grid.axes_llc.set_yticks([-2,0,2])defdemo_grid_with_each_cbar_labelled(fig):"""    A grid of 2x2 images. Each image has its own colorbar.    """grid=AxesGrid(fig,144,# similar to subplot(144)nrows_ncols=(2,2),axes_pad=(0.45,0.15),label_mode="1",share_all=True,cbar_location="right",cbar_mode="each",cbar_size="7%",cbar_pad="2%",)Z,extent=get_demo_image()# Use a different colorbar range every timelimits=((0,1),(-2,2),(-1.7,1.4),(-1.5,1))foriinrange(4):im=grid[i].imshow(Z,extent=extent,interpolation="nearest",vmin=limits[i][0],vmax=limits[i][1])grid.cbar_axes[i].colorbar(im)fori,caxinenumerate(grid.cbar_axes):cax.set_yticks((limits[i][0],limits[i][1]))# This affects all axes because we set share_all = True.grid.axes_llc.set_xticks([-2,0,2])grid.axes_llc.set_yticks([-2,0,2])if1:F=plt.figure(1,(10.5,2.5))F.subplots_adjust(left=0.05,right=0.95)demo_simple_grid(F)demo_grid_with_single_cbar(F)demo_grid_with_each_cbar(F)demo_grid_with_each_cbar_labelled(F)plt.draw()plt.show()

Keywords: python, matplotlib, pylab, example, codex (seeSearch examples)

© Copyright 2002 - 2012 John Hunter, Darren Dale, Eric Firing, Michael Droettboom and the Matplotlib development team; 2012 - 2016 The Matplotlib development team. Last updated on Feb 20, 2017. Created usingSphinx 1.5.2.

[8]ページ先頭

©2009-2025 Movatter.jp