Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
yt-project
GitHub Repository: yt-project/yt
Path: blob/main/doc/source/cookbook/multi_plot_3x2_FRB.py
928 views
1
import numpy as np
2
from matplotlib.colors import LogNorm
3
4
import yt
5
from yt.visualization.api import get_multi_plot
6
7
fn = "Enzo_64/RD0006/RedshiftOutput0006" # dataset to load
8
9
# load data and get center value and center location as maximum density location
10
ds = yt.load(fn)
11
v, c = ds.find_max(("gas", "density"))
12
13
# set up our Fixed Resolution Buffer parameters: a width, resolution, and center
14
width = (1.0, "unitary")
15
res = [1000, 1000]
16
# get_multi_plot returns a containing figure, a list-of-lists of axes
17
# into which we can place plots, and some axes that we'll put
18
# colorbars.
19
20
# it accepts: # of x-axis plots, # of y-axis plots, and how the
21
# colorbars are oriented (this also determines where they go: below
22
# in the case of 'horizontal', on the right in the case of
23
# 'vertical'), bw is the base-width in inches (4 is about right for
24
# most cases)
25
26
orient = "horizontal"
27
fig, axes, colorbars = get_multi_plot(2, 3, colorbar=orient, bw=6)
28
29
# Now we follow the method of "multi_plot.py" but we're going to iterate
30
# over the columns, which will become axes of slicing.
31
plots = []
32
for ax in range(3):
33
sli = ds.slice(ax, c[ax])
34
frb = sli.to_frb(width, res)
35
den_axis = axes[ax][0]
36
temp_axis = axes[ax][1]
37
38
# here, we turn off the axes labels and ticks, but you could
39
# customize further.
40
for ax in (den_axis, temp_axis):
41
ax.xaxis.set_visible(False)
42
ax.yaxis.set_visible(False)
43
44
# converting our fixed resolution buffers to NDarray so matplotlib can
45
# render them
46
dens = np.array(frb["gas", "density"])
47
temp = np.array(frb["gas", "temperature"])
48
49
plots.append(den_axis.imshow(dens, norm=LogNorm()))
50
plots[-1].set_clim((5e-32, 1e-29))
51
plots[-1].set_cmap("bds_highcontrast")
52
53
plots.append(temp_axis.imshow(temp, norm=LogNorm()))
54
plots[-1].set_clim((1e3, 1e8))
55
plots[-1].set_cmap("hot")
56
57
# Each 'cax' is a colorbar-container, into which we'll put a colorbar.
58
# the zip command creates triples from each element of the three lists
59
# . Note that it cuts off after the shortest iterator is exhausted,
60
# in this case, titles.
61
titles = [
62
r"$\mathrm{density}\ (\mathrm{g\ cm^{-3}})$",
63
r"$\mathrm{temperature}\ (\mathrm{K})$",
64
]
65
for p, cax, t in zip(plots, colorbars, titles):
66
# Now we make a colorbar, using the 'image' we stored in plots
67
# above. note this is what is *returned* by the imshow method of
68
# the plots.
69
cbar = fig.colorbar(p, cax=cax, orientation=orient)
70
cbar.set_label(t)
71
72
# And now we're done!
73
fig.savefig(f"{ds}_3x2.png")
74
75