"""
This recipe shows a slightly-fancy way to save a couple plots at a lot of
different widths, ensuring that across the plots we have the same min/max for
the colorbar.
"""
from yt.mods import *

fn = "RedshiftOutput0005" # parameter file to load
pf = load(fn) # load data

pc = PlotCollection(pf, center=[0.5, 0.5, 0.5]) # We get our Plot Collection object

# Note that when we save, we will be using string formatting to change all of
# the bits in here.  You can add more, or remove some, if you like.
fn = "%(bn)s_%(width)010i_%(unit)s" # template for image file names

# Now let's set up the widths we want to use.
widths = [ (2, "mpc"), (1000, 'kpc')]
# We could add on more of these with:
#  widths += [ ... ]

# Now we add a slice for x and y.
pc.add_slice("Density", 0)
pc.add_slice("Density", 1)

# So for all of our widths, we will set the width of the plot and then make
# sure that our limits for the colorbar are the min/max across the three plots.
# Then we save!  Each saved file will have a descriptive name, so we can tell
# them apart.

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)
    # This is the string formatting we talked about earlier
    d = {'bn':pf.basename, 'width':width, 'unit':unit}
    pc.save(fn % d)

