Path: blob/main/doc/source/cookbook/multiplot_phaseplot.py
928 views
import matplotlib.pyplot as plt1from mpl_toolkits.axes_grid1 import AxesGrid23import yt45fig = plt.figure()67# See http://matplotlib.org/mpl_toolkits/axes_grid/api/axes_grid_api.html8grid = AxesGrid(9fig,10(0.085, 0.085, 0.83, 0.83),11nrows_ncols=(1, 2),12axes_pad=0.05,13label_mode="L",14share_all=True,15cbar_location="right",16cbar_mode="single",17cbar_size="3%",18cbar_pad="0%",19aspect=False,20)2122for i, SnapNum in enumerate([10, 40]):23# Load the data and create a single plot24ds = yt.load("enzo_tiny_cosmology/DD00%2d/DD00%2d" % (SnapNum, SnapNum))25ad = ds.all_data()26p = yt.PhasePlot(27ad,28("gas", "density"),29("gas", "temperature"),30[31("gas", "mass"),32],33weight_field=None,34)3536# Ensure the axes and colorbar limits match for all plots37p.set_xlim(1.0e-32, 8.0e-26)38p.set_ylim(1.0e1, 2.0e7)39p.set_zlim(("gas", "mass"), 1e42, 1e46)4041# This forces the ProjectionPlot to redraw itself on the AxesGrid axes.42plot = p.plots["gas", "mass"]43plot.figure = fig44plot.axes = grid[i].axes45if i == 0:46plot.cax = grid.cbar_axes[i]4748# Actually redraws the plot.49p.render()5051# Modify the axes properties **after** p.render() so that they52# are not overwritten.53plot.axes.xaxis.set_minor_locator(plt.LogLocator(base=10.0, subs=[2.0, 5.0, 8.0]))5455plt.savefig("multiplot_phaseplot.png")565758