"""
This is a simple recipe to show how to open a dataset and then plot a slice
through it, centered at its most dense point.  For more information, see
:func:`~yt.raven.get_multi_plot`.
"""
from yt.mods import * # set up our namespace
import matplotlib.colorbar as cb

fn = "RedshiftOutput0005" # parameter file to load
orient = 'horizontal'

pf = load(fn) # load data

# There's a lot in here:
#   From this we get a containing figure, a list-of-lists of axes into which we
#   can place plots, and some axes that we'll put colorbars.
# We feed it:
#   Number of plots on the x-axis, number of plots on the y-axis, and how we
#   want our colorbars oriented.  (This governs where they will go, too.
#   bw is the base-width in inches, but 4 is about right for most cases.
fig, axes, colorbars = raven.get_multi_plot( 2, 3, colorbar=orient, bw = 4)

# We'll use a plot collection, just for convenience's sake
pc = PlotCollection(pf, center=[0.5, 0.5, 0.5])

# Now we follow the method of "multi_plot.py" but we're going to iterate
# over the columns, which will become axes of slicing.
for ax in range(3):
    p = pc.add_slice("Density", ax, figure = fig, axes = axes[ax][0],
                     use_colorbar=False)
    p.set_cmap("bds_highcontrast") # this is our colormap
    p.set_zlim(5e-32, 1e-29)
    # We do this again, but this time we take the 1-index column.
    p = pc.add_slice("Temperature", ax, figure=fig, axes=axes[ax][1],
                     use_colorbar=False)
    p.set_zlim(1e3, 3e4) # Set this so it's the same for all.
    p.set_cmap("hot") # a different colormap

pc.set_width(5.0, 'mpc') # change width of both plots

# Each 'p' is a plot -- this is the Density plot and the Temperature plot.
# Each 'cax' is a colorbar-container, into which we'll put a colorbar.
# zip means, give these two me together.  Note that it cuts off after the
# shortest iterator is exhausted, in this case pc.plots.
for p, cax in zip(pc.plots, colorbars):
    # Now we make a colorbar, using the 'image' attribute of the plot.
    # 'image' is usually not accessed; we're making a special exception here,
    # though.  'image' will tell the colorbar what the limits of the data are.
    cbar = cb.Colorbar(cax, p.image, orientation=orient)
    # Now, we have to do a tiny bit of magic -- we tell the plot what its
    # colorbar is, and then we tell the plot to set the label of that colorbar.
    p.colorbar = cbar
    p._autoset_label()

# And now we're done!  Note that we're calling a method of the figure, not the
# PlotCollection.
fig.savefig("%s_3x2" % pf)
