Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
yt-project
GitHub Repository: yt-project/yt
Path: blob/main/doc/source/cookbook/multiplot_phaseplot.py
928 views
1
import matplotlib.pyplot as plt
2
from mpl_toolkits.axes_grid1 import AxesGrid
3
4
import yt
5
6
fig = plt.figure()
7
8
# See http://matplotlib.org/mpl_toolkits/axes_grid/api/axes_grid_api.html
9
grid = AxesGrid(
10
fig,
11
(0.085, 0.085, 0.83, 0.83),
12
nrows_ncols=(1, 2),
13
axes_pad=0.05,
14
label_mode="L",
15
share_all=True,
16
cbar_location="right",
17
cbar_mode="single",
18
cbar_size="3%",
19
cbar_pad="0%",
20
aspect=False,
21
)
22
23
for i, SnapNum in enumerate([10, 40]):
24
# Load the data and create a single plot
25
ds = yt.load("enzo_tiny_cosmology/DD00%2d/DD00%2d" % (SnapNum, SnapNum))
26
ad = ds.all_data()
27
p = yt.PhasePlot(
28
ad,
29
("gas", "density"),
30
("gas", "temperature"),
31
[
32
("gas", "mass"),
33
],
34
weight_field=None,
35
)
36
37
# Ensure the axes and colorbar limits match for all plots
38
p.set_xlim(1.0e-32, 8.0e-26)
39
p.set_ylim(1.0e1, 2.0e7)
40
p.set_zlim(("gas", "mass"), 1e42, 1e46)
41
42
# This forces the ProjectionPlot to redraw itself on the AxesGrid axes.
43
plot = p.plots["gas", "mass"]
44
plot.figure = fig
45
plot.axes = grid[i].axes
46
if i == 0:
47
plot.cax = grid.cbar_axes[i]
48
49
# Actually redraws the plot.
50
p.render()
51
52
# Modify the axes properties **after** p.render() so that they
53
# are not overwritten.
54
plot.axes.xaxis.set_minor_locator(plt.LogLocator(base=10.0, subs=[2.0, 5.0, 8.0]))
55
56
plt.savefig("multiplot_phaseplot.png")
57
58