Path: blob/main/doc/source/cookbook/multiplot_2x2_time_series.py
928 views
import matplotlib.pyplot as plt1from mpl_toolkits.axes_grid1 import AxesGrid23import yt45fns = [6"Enzo_64/DD0005/data0005",7"Enzo_64/DD0015/data0015",8"Enzo_64/DD0025/data0025",9"Enzo_64/DD0035/data0035",10]1112fig = plt.figure()1314# See http://matplotlib.org/mpl_toolkits/axes_grid/api/axes_grid_api.html15# These choices of keyword arguments produce a four panel plot with a single16# shared narrow colorbar on the right hand side of the multipanel plot. Axes17# labels are drawn for all plots since we're slicing along different directions18# for each plot.19grid = AxesGrid(20fig,21(0.075, 0.075, 0.85, 0.85),22nrows_ncols=(2, 2),23axes_pad=0.05,24label_mode="L",25share_all=True,26cbar_location="right",27cbar_mode="single",28cbar_size="3%",29cbar_pad="0%",30)3132for i, fn in enumerate(fns):33# Load the data and create a single plot34ds = yt.load(fn) # load data35p = yt.ProjectionPlot(ds, "z", ("gas", "density"), width=(55, "Mpccm"))3637# Ensure the colorbar limits match for all plots38p.set_zlim(("gas", "density"), 1e-4, 1e-2)3940# This forces the ProjectionPlot to redraw itself on the AxesGrid axes.41plot = p.plots["gas", "density"]42plot.figure = fig43plot.axes = grid[i].axes44plot.cax = grid.cbar_axes[i]4546# Finally, this actually redraws the plot.47p.render()4849plt.savefig("multiplot_2x2_time_series.png")505152