Sometimes you need a lot of flexibility in creating plots. While the
PlotWindow
provides an easy to
use object that can create nice looking, publication quality plots with a
minimum of effort, there are often times when its ease of use conflicts with
your need to change the font only on the x-axis, or whatever your
need/desire/annoying coauthor requires. To that end, yt provides a number of
ways of getting the raw data that goes into a plot to you in the form of a one
or two dimensional dataset that you can plot using any plotting method you like.
matplotlib or another python library are easiest, but these methods allow you to
take your data and plot it in gnuplot, or any unnamed commercial plotting
packages.
Note that the index object associated with your snapshot file contains a
list of plots you’ve made in ds.plots
.
For slices and projects, yt provides a manual plotting interface based on
the FixedResolutionBuffer
(hereafter
referred to as FRB) object. Despite its somewhat unwieldy name, at its heart, an
FRB is a very simple object: it’s essentially a window into your data: you give
it a center and a width or a left and right edge, and an image resolution, and
the FRB returns a fully pixelized image. The simplest way to
generate an FRB is to use the .to_frb(width, resolution, center=None)
method
of any data two-dimensional data object:
Note that in the above example the axes tick marks indicate pixel indices. If you
want to represent physical distances on your plot axes, you will need to use the
extent
keyword of the imshow
function.
The FRB is a very small object that can be deleted and recreated quickly (in
fact, this is how PlotWindow
plots work behind the scenes). Furthermore, you
can add new fields in the same “window”, and each of them can be plotted with
their own zlimit. This is quite useful for creating a mosaic of the same region
in space with Density, Temperature, and x-velocity, for example. Each of these
quantities requires a substantially different set of limits.
A more complex example, showing a few yt helper functions that can make setting up multiple axes with colorbars easier than it would be using only matplotlib can be found in the Advanced Multi-Plot Multi-Panel cookbook recipe.
The FRB can be modified by using set of predefined filters in order to e.g. create realistically looking, mock observation images out of simulation data. Applying filter is an irreversible operation, hence the order in which you are using them matters.
Currently available filters:
This is perhaps the simplest thing to do. yt provides a number of one
dimensional objects, and these return a 1-D numpy array of their contents with
direct dictionary access. As a simple example, take a
YTOrthoRayBase
object, which can be
created from a index by calling pf.ortho_ray(axis, center)
.
Of course, you’ll likely want to do something more sophisticated than using the matplotlib defaults, but this gives the general idea.