Making plots can be considered one of the simplest things to do in yt, and at its most primitive you can simply declare which plots to make.
The following recipe opens the parameter file, creates a ‘collection’ of plots, adds a few slices, and then saves it at a fixed width. (cookbook_single_width_plot.py)
1 2 3 4 5 6 7 8 9 | from yt.mods import *
pf = get_pf()
pc = raven.PlotCollection(pf)
pc.add_slice("Density",0)
pc.add_slice("Density",1)
pc.add_slice("Density",2)
pc.set_width(100.0,'kpc')
pc.save("my_data0001_100kpc")
|
The ‘save’ command encodes the name of the field into the filename. It is more efficient to ‘switch’ a field than to add a new slice with a different field. (cookbook_multiple_fields_single_width_plot.py)
1 2 3 4 5 6 7 8 9 10 11 12 | from yt.mods import *
pf = get_pf()
fields = ["Density", "Temperature", "x-velocity"]
pc = raven.PlotCollection(pf)
pc.add_slice(fields[0],0)
pc.add_slice(fields[0],1)
pc.add_slice(fields[0],2)
pc.set_width(100.0,'kpc')
for field in fields:
pc.switch_field(field)
pc.save("my_data0001_100kpc")
|
We can zoom in on our slice very easily, and we can define it to do that and vary units, too, thus ensuring we have a consistent set of plots. (cookbook_multiple_widths_plot.py)
Note
We do some fancy footwork here with the creation of my_pairs but it is an idiom that can be applied elsewhere.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | from yt.mods import *
pf = get_pf()
widths = [1000.0, 100.0, 10.0, 1.0]
units = ['mpc','kpc','pc','au']
my_pairs = [ (w,u) for u in units for w in widths ]
pc = raven.PlotCollection(pf)
pc.add_slice("Density",0)
pc.add_slice("Density",1)
pc.add_slice("Density",2)
for w, u in my_pairs:
pc.set_width(w,u)
pc.save("my_data0001_%05i%s" % (w, u))
|
Because of the way the slices are created and the fields handled, we set our outer loop to be over the field and the inner loop to be over the widths. (cookbook_multiple_fields_multiple_widths_plot.py)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | from yt.mods import *
pf = get_pf()
fields = ["Density", "Temperature", "x-velocity"]
widths = [1000.0, 100.0, 10.0, 1.0]
units = ['mpc','kpc','pc','au']
my_pairs = [ (w,u) for u in units for w in widths ]
pc = raven.PlotCollection(pf)
pc.add_slice(fields[0],0)
pc.add_slice(fields[0],1)
pc.add_slice(fields[0],2)
for field in fields:
pc.switch_field(field)
for w, u in my_pairs:
pc.set_width(w,u)
pc.save("my_data0001_%05i%s" % (w, u))
|
This is an idiom with which one can link several plots in widths, naming, and colorbars. (cookbook_linked_plot_save.py)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 | from yt.mods import *
pf = get_pf()
pc = raven.PlotCollection(pf)
fn = "%(bn)s_%(width)010i_%(unit)s" # template for image file names
widths = []
widths += [(i, "kpc") for i in [1]]
widths += [(i, "pc") for i in [1000, 100, 10, 1]]
widths += [(i, "au") for i in [1000, 100, 10, 1]]
widths += [(i, "rsun") for i in [1000, 100, 10, 1]]
def linked_save(pf, pc):
for width, unit in widths:
pc.set_width(width,unit)
vmin = min([p.norm.vmin for p in pc.plots])
vmax = max([p.norm.vmax for p in pc.plots])
pc.set_zlim(vmin,vmax)
d = {'bn':pf.basename, 'width':width, 'unit':unit}
print pc.save(fn % d)
pc.add_slice("MachNumber", 0)
pc.add_slice("MachNumber", 1)
pc.add_slice("MachNumber", 2)
linked_save(pf, pc)
|