Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
yt-project
GitHub Repository: yt-project/yt
Path: blob/main/doc/source/cookbook/multiplot_2x2_time_series.py
928 views
1
import matplotlib.pyplot as plt
2
from mpl_toolkits.axes_grid1 import AxesGrid
3
4
import yt
5
6
fns = [
7
"Enzo_64/DD0005/data0005",
8
"Enzo_64/DD0015/data0015",
9
"Enzo_64/DD0025/data0025",
10
"Enzo_64/DD0035/data0035",
11
]
12
13
fig = plt.figure()
14
15
# See http://matplotlib.org/mpl_toolkits/axes_grid/api/axes_grid_api.html
16
# These choices of keyword arguments produce a four panel plot with a single
17
# shared narrow colorbar on the right hand side of the multipanel plot. Axes
18
# labels are drawn for all plots since we're slicing along different directions
19
# for each plot.
20
grid = AxesGrid(
21
fig,
22
(0.075, 0.075, 0.85, 0.85),
23
nrows_ncols=(2, 2),
24
axes_pad=0.05,
25
label_mode="L",
26
share_all=True,
27
cbar_location="right",
28
cbar_mode="single",
29
cbar_size="3%",
30
cbar_pad="0%",
31
)
32
33
for i, fn in enumerate(fns):
34
# Load the data and create a single plot
35
ds = yt.load(fn) # load data
36
p = yt.ProjectionPlot(ds, "z", ("gas", "density"), width=(55, "Mpccm"))
37
38
# Ensure the colorbar limits match for all plots
39
p.set_zlim(("gas", "density"), 1e-4, 1e-2)
40
41
# This forces the ProjectionPlot to redraw itself on the AxesGrid axes.
42
plot = p.plots["gas", "density"]
43
plot.figure = fig
44
plot.axes = grid[i].axes
45
plot.cax = grid.cbar_axes[i]
46
47
# Finally, this actually redraws the plot.
48
p.render()
49
50
plt.savefig("multiplot_2x2_time_series.png")
51
52