# yt.visualization.plot_window module¶

class yt.visualization.plot_window.AxisAlignedSlicePlot(ds, axis, fields, center='c', width=None, axes_unit=None, origin='center-window', right_handed=True, fontsize=18, field_parameters=None, window_size=8.0, aspect=None, data_source=None, buff_size=800, 800)[source]

Creates a slice plot from a dataset

Given a ds object, an axis to slice along, and a field name string, this will return a PWViewerMPL object containing the plot.

The plot can be updated using one of the many helper functions defined in PlotWindow.

Parameters
• ds (Dataset) – This is the dataset object corresponding to the simulation output to be plotted.

• axis (int or one of 'x', 'y', 'z') – An int corresponding to the axis to slice along (0=x, 1=y, 2=z) or the axis name itself

• fields (string) – The name of the field(s) to be plotted.

• center (A sequence of floats, a string, or a tuple.) – The coordinate of the center of the image. If set to ‘c’, ‘center’ or left blank, the plot is centered on the middle of the domain. If set to ‘max’ or ‘m’, the center will be located at the maximum of the (‘gas’, ‘density’) field. Centering on the max or min of a specific field is supported by providing a tuple such as (“min”,”temperature”) or (“max”,”dark_matter_density”). Units can be specified by passing in center as a tuple containing a coordinate and string unit name or by passing in a YTArray. If a list or unitless array is supplied, code units are assumed.

• width (tuple or a float.) –

Width can have four different formats to support windows with variable x and y widths. They are:

format

example

(float, string)

(10,’kpc’)

((float, string), (float, string))

((10,’kpc’),(15,’kpc’))

float

0.2

(float, float)

(0.2, 0.3)

For example, (10, ‘kpc’) requests a plot window that is 10 kiloparsecs wide in the x and y directions, ((10,’kpc’),(15,’kpc’)) requests a window that is 10 kiloparsecs wide along the x axis and 15 kiloparsecs wide along the y axis. In the other two examples, code units are assumed, for example (0.2, 0.3) requests a plot that has an x width of 0.2 and a y width of 0.3 in code units. If units are provided the resulting plot axis labels will use the supplied units.

• origin (string or length 1, 2, or 3 sequence.) –

The location of the origin of the plot coordinate system. This is typically represented by a ‘-‘ separated string or a tuple of strings. In the first index the y-location is given by ‘lower’, ‘upper’, or ‘center’. The second index is the x-location, given as ‘left’, ‘right’, or ‘center’. Finally, whether the origin is applied in ‘domain’ space, plot ‘window’ space or ‘native’ simulation coordinate system is given. For example, both ‘upper-right-domain’ and [‘upper’, ‘right’, ‘domain’] place the origin in the upper right hand corner of domain space. If x or y are not given, a value is inferred. For instance, ‘left-domain’ corresponds to the lower-left hand corner of the simulation domain, ‘center-domain’ corresponds to the center of the simulation domain, or ‘center-window’ for the center of the plot window. In the event that none of these options place the origin in a desired location, a sequence of tuples and a string specifying the coordinate space can be given. If plain numeric types are input, units of code_length are assumed. Further examples:

format

example

’{space}’

’domain’

’{xloc}-{space}’

’left-window’

’{yloc}-{space}’

’upper-domain’

’{yloc}-{xloc}-{space}’

’lower-right-window’

(‘{space}’,)

(‘window’,)

(‘{xloc}’, ‘{space}’)

(‘right’, ‘domain’)

(‘{yloc}’, ‘{space}’)

(‘lower’, ‘window’)

(‘{yloc}’, ‘{xloc}’, ‘{space}’)

(‘lower’, ‘right’, ‘window’)

((yloc, ‘{unit}’), (xloc, ‘{unit}’), ‘{space}’)

((0, ‘m’), (.4, ‘m’), ‘window’)

(xloc, yloc, ‘{space}’)

(0.23, 0.5, ‘domain’)

• axes_unit (string) – The name of the unit for the tick labels on the x and y axes. Defaults to None, which automatically picks an appropriate unit. If axes_unit is ‘1’, ‘u’, or ‘unitary’, it will not display the units, and only show the axes name.

• right_handed (boolean) – Whether the implicit east vector for the image generated is set to make a right handed coordinate system with a normal vector, the direction of the ‘window’ into the data.

• fontsize (integer) – The size of the fonts for the axis, colorbar, and tick labels.

• field_parameters (dictionary) – A dictionary of field parameters than can be accessed by derived fields.

• data_source (YTSelectionContainer object) – Object to be used for data selection. Defaults to ds.all_data(), a region covering the full domain

• buff_size (length 2 sequence) – Size of the buffer to use for the image, i.e. the number of resolution elements used. Effectively sets a resolution limit to the image if buff_size is smaller than the finest gridding.

Examples

This will save an image in the file ‘sliceplot_Density.png’

>>> from yt import load
>>> ds = load("IsolatedGalaxy/galaxy0030/galaxy0030")
>>> p = SlicePlot(ds, 2, "density", "c", (20, "kpc"))
>>> p.save("sliceplot")

annotate_clear(index=None)

Clear callbacks from the plot. If index is not set, clear all callbacks. If index is set, clear that index (ie 0 is the first one created, 1 is the 2nd one created, -1 is the last one created, etc.)

Note

Deprecated in favor of clear_annotations.

property bounds
clear_annotations(index=None)

Clear callbacks from the plot. If index is not set, clear all callbacks. If index is set, clear that index (ie 0 is the first one created, 1 is the 2nd one created, -1 is the last one created, etc.)

display(name=None, mpl_kwargs=None)

Will attempt to show the plot in in an IPython notebook. Failing that, the plot will be saved to disk.

export_to_mpl_figure(nrows_ncols, axes_pad=1.0, label_mode='L', cbar_location='right', cbar_size='5%', cbar_mode='each', cbar_pad='0%')

Creates a matplotlib figure object with the specified axes arrangement, nrows_ncols, and maps the underlying figures to the matplotlib axes. Note that all of these parameters are fed directly to the matplotlib ImageGrid class to create the new figure layout.

Parameters
• nrows_ncols (tuple) – the number of rows and columns of the axis grid (e.g., nrows_ncols=(2,2,))

• axes_pad (float) – padding between axes in inches

• label_mode (one of "L", "1", "all") – arrangement of axes that are labeled

• cbar_location (one of "left", "right", "bottom", "top") – where to place the colorbar

• cbar_size (string (percentage)) – scaling of the colorbar (e.g., “5%”)

• cbar_mode (one of "each", "single", "edge", None) – how to represent the colorbar

• cbar_pad (string (percentage)) – padding between the axis and colorbar (e.g. “5%”)

Returns

Return type

The return is a matplotlib figure object.

Examples

>>> import yt
>>> ds = yt.load_sample("IsolatedGalaxy")
>>> fields = ["density", "velocity_x", "velocity_y", "velocity_magnitude"]
>>> p = yt.SlicePlot(ds, "z", fields)
>>> p.set_log("velocity_x", False)
>>> p.set_log("velocity_y", False)
>>> fig = p.export_to_mpl_figure((2, 2))
>>> fig.tight_layout()
>>> fig.savefig("test.png")

property frb

The frb property.

get_log(field)

get the transform type of a field.

Parameters

field (string) – the field to get a transform if field == ‘all’, applies to all plots.

hide_axes(field=None, draw_frame=False)

Hides the axes for a plot and updates the size of the plot accordingly. Defaults to operating on all fields for a PlotContainer object.

Parameters
• field (string, field tuple, or list of strings or field tuples (optional)) – The name of the field(s) that we want to hide the axes.

• draw_frame (boolean) – If True, the axes frame will still be drawn. Defaults to False. See note below for more details.

Examples

This will save an image with no axes.

>>> import yt
>>> ds = yt.load("IsolatedGalaxy/galaxy0030/galaxy0030")
>>> s = SlicePlot(ds, 2, "density", "c", (20, "kpc"))
>>> s.hide_axes()
>>> s.save()


This will save an image with no axis or colorbar.

>>> import yt
>>> ds = yt.load("IsolatedGalaxy/galaxy0030/galaxy0030")
>>> s = SlicePlot(ds, 2, "density", "c", (20, "kpc"))
>>> s.hide_axes()
>>> s.hide_colorbar()
>>> s.save()


Note

By default, when removing the axes, the patch on which the axes are drawn is disabled, making it impossible to later change e.g. the background colour. To force the axes patch to be displayed while still hiding the axes, set the draw_frame keyword argument to True.

hide_colorbar(field=None)

Hides the colorbar for a plot and updates the size of the plot accordingly. Defaults to operating on all fields for a PlotContainer object.

Parameters

field (string, field tuple, or list of strings or field tuples (optional)) – The name of the field(s) that we want to hide the colorbar. If None or ‘all’ is provided, will default to using all fields available for this object.

Examples

This will save an image with no colorbar.

>>> import yt
>>> ds = yt.load("IsolatedGalaxy/galaxy0030/galaxy0030")
>>> s = SlicePlot(ds, 2, "density", "c", (20, "kpc"))
>>> s.hide_colorbar()
>>> s.save()


This will save an image with no axis or colorbar.

>>> import yt
>>> ds = yt.load("IsolatedGalaxy/galaxy0030/galaxy0030")
>>> s = SlicePlot(ds, 2, "density", "c", (20, "kpc"))
>>> s.hide_axes()
>>> s.hide_colorbar()
>>> s.save()

list_annotations()

List the current callbacks for the plot, along with their index. This index can be used with clear_annotations to remove a callback from the current plot.

pan(deltas)

Pan the image by specifying absolute code unit coordinate deltas.

Parameters

deltas (Two-element sequence of floats, quantities, or (float, unit)) –

tuples.

(delta_x, delta_y). If a unit is not supplied the unit is assumed to be code_length.

pan_rel(deltas)

Pan the image by specifying relative deltas, to the FOV.

Parameters

deltas (sequence of floats) – (delta_x, delta_y) in relative code unit coordinates

piter(*args, **kwargs)
refresh()
run_callbacks()
save(name=None, suffix='.png', mpl_kwargs=None)

saves the plot to disk.

Parameters
• name (string or tuple) – The base of the filename. If name is a directory or if name is not set, the filename of the dataset is used. For a tuple, the resulting path will be given by joining the elements of the tuple

• suffix (string) – Specify the image type by its suffix. If not specified, the output type will be inferred from the filename. Defaults to PNG.

• mpl_kwargs (dict) – A dict of keyword arguments to be passed to matplotlib.

• slc.save(mpl_kwargs={"bbox_inches" (>>>) –

set_antialias(aa)

Turn antialiasing on or off.

Parameters

aa (boolean) –

set_axes_unit(unit_name)

Set the unit for display on the x and y axes of the image.

Parameters

unit_name (string or two element tuple of strings) – A unit, available for conversion in the dataset, that the image extents will be displayed in. If set to None, any previous units will be reset. If the unit is None, the default is chosen. If unit_name is ‘1’, ‘u’, or ‘unitary’, it will not display the units, and only show the axes name. If unit_name is a tuple, the first element is assumed to be the unit for the x axis and the second element the unit for the y axis.

Raises

YTUnitNotRecognized – If the unit is not known, this will be raised.

Examples

>>> from yt import load
>>> ds = load("IsolatedGalaxy/galaxy0030/galaxy0030")
>>> p = ProjectionPlot(ds, "y", "Density")
>>> p.set_axes_unit("kpc")

set_background_color(field, color=None)

set the background color to match provided color

Parameters
• field (string) – the field to set the colormap if field == ‘all’, applies to all plots.

• color (string or RGBA tuple (optional)) – if set, set the background color to this color if unset, background color is set to the bottom value of the color map

set_buff_size(size)

Sets a new buffer size for the fixed resolution buffer

Parameters

size (int or two element sequence of ints) – The number of data elements in the buffer on the x and y axes. If a scalar is provided, then the buffer is assumed to be square.

set_cbar_minorticks(field, state)

turn colorbar minor ticks “on” or “off” in the current plot, following state

Parameters
• field (string) – the field to remove colorbar minorticks

• state (string) – the state indicating ‘on’ or ‘off’

set_center(new_center, unit='code_length')

Sets a new center for the plot window

Parameters
• new_center (two element sequence of floats) – The coordinates of the new center of the image in the coordinate system defined by the plot axes. If the unit keyword is not specified, the coordinates are assumed to be in code units.

• unit (string) – The name of the unit new_center is given in. If new_center is a YTArray or tuple of YTQuantities, this keyword is ignored.

set_cmap(field, cmap)

set the colormap for one of the fields

Parameters
• field (string) – the field to set the colormap if field == ‘all’, applies to all plots.

• cmap (string or tuple) – If a string, will be interpreted as name of the colormap. If a tuple, it is assumed to be of the form (name, type, number) to be used for palettable functionality. (name, type, number, bool) can be used to specify if a reverse colormap is to be used.

set_colorbar_label(field, label)

Sets the colorbar label.

Parameters
• field (str or tuple) – The name of the field to modify the label for.

• label (str) – The new label

• plot.set_colorbar_label( (>>>) –

• ("gas", "density"), "Dark Matter Density (g cm$^{-3}$)" (..) –

• ) (..) –

set_colorbar_minorticks(field, state)

turn colorbar minor ticks on or off in the current plot

Displaying minor ticks reduces performance; turn them off using set_colorbar_minorticks(‘all’, False) if drawing speed is a problem.

Parameters
• field (string) – the field to remove colorbar minorticks if field == ‘all’, applies to all plots.

• state (bool) – the state indicating ‘on’ (True) or ‘off’ (False)

set_figure_size(size)

Sets a new figure size for the plot

Parameters

size (float) – The size of the figure on the longest axis (in units of inches), including the margins but not the colorbar.

set_font(font_dict=None)

Set the font and font properties.

Parameters

font_dict (dict) –

A dict of keyword parameters to be passed to matplotlib.font_manager.FontProperties.

Possible keys include:

• family - The font family. Can be serif, sans-serif, cursive, ‘fantasy’ or ‘monospace’.

• style - The font style. Either normal, italic or oblique.

• color - A valid color string like ‘r’, ‘g’, ‘red’, ‘cobalt’, and ‘orange’.

• variant - Either normal or small-caps.

• size - Either a relative value of xx-small, x-small, small, medium, large, x-large, xx-large or an absolute font size, e.g. 12

• stretch - A numeric value in the range 0-1000 or one of ultra-condensed, extra-condensed, condensed, semi-condensed, normal, semi-expanded, expanded, extra-expanded or ultra-expanded

• weight - A numeric value in the range 0-1000 or one of ultralight, light, normal, regular, book, medium, roman, semibold, demibold, demi, bold, heavy, extra bold, or black

See the matplotlib font manager API documentation for more details. https://matplotlib.org/stable/api/font_manager_api.html

Notes

Mathtext axis labels will only obey the size and color keyword.

Examples

This sets the font to be 24-pt, blue, sans-serif, italic, and bold-face.

>>> slc = SlicePlot(ds, "x", "Density")
>>> slc.set_font(
...     {
...         "family": "sans-serif",
...         "style": "italic",
...         "weight": "bold",
...         "size": 24,
...         "color": "blue",
...     }
... )

set_font_size(size)

Set the size of the font used in the plot

This sets the font size by calling the set_font function. See set_font for more font customization options.

Parameters
• size (float) –

• absolute size of the font in points (1 pt = 1/72 inch) (The) –

set_log(field, log, linthresh=None, symlog_auto=False)

set a field to log, linear, or symlog.

Symlog scaling is a combination of linear and log, where from 0 to a threshold value, it operates as linear, and then beyond that it operates as log. Symlog can also work with negative values in log space as well as negative and positive values simultaneously and symmetrically. If symlog scaling is desired, please set log=True and either set symlog_auto=True or select a alue for linthresh.

Parameters
• field (string) – the field to set a transform if field == ‘all’, applies to all plots.

• log (boolean) – Log on/off: on means log scaling; off means linear scaling. Unless a linthresh is set or symlog_auto is set in which case symlog is used.

• linthresh (float, optional) – when using symlog scaling, linthresh is the value at which scaling transitions from linear to logarithmic. linthresh must be positive. Note: setting linthresh will automatically enable symlog scale

• symlog_auto (boolean) – if symlog_auto is True, then yt will use symlog scaling and attempt to determine a linthresh automatically. Setting a linthresh manually overrides this value.

set_minorticks(field, state)

Turn minor ticks on or off in the current plot.

Displaying minor ticks reduces performance; turn them off using set_minorticks(‘all’, False) if drawing speed is a problem.

Parameters
• field (string) – the field to remove minorticks if field == ‘all’, applies to all plots.

• state (bool) – the state indicating ‘on’ (True) or ‘off’ (False)

set_mpl_projection(mpl_proj)

Set the matplotlib projection type with a cartopy transform function

Given a string or a tuple argument, this will project the data onto the plot axes with the chosen transform function.

Assumes that the underlying data has a PlateCarree transform type.

To annotate the plot with coastlines or other annotations, _setup_plots() will need to be called after this function to make the axes available for annotation.

Parameters

mpl_proj (string or tuple) – if passed as a string, mpl_proj is the specified projection type, if passed as a tuple, then tuple will take the form of ("ProjectionType", (args)) or ("ProjectionType", (args), {kwargs}) Valid projection type options include: ‘PlateCarree’, ‘LambertConformal’, ‘LabmbertCylindrical’, ‘Mercator’, ‘Miller’, ‘Mollweide’, ‘Orthographic’, ‘Robinson’, ‘Stereographic’, ‘TransverseMercator’, ‘InterruptedGoodeHomolosine’, ‘RotatedPole’, ‘OGSB’, ‘EuroPP’, ‘Geostationary’, ‘Gnomonic’, ‘NorthPolarStereo’, ‘OSNI’, ‘SouthPolarStereo’, ‘AlbersEqualArea’, ‘AzimuthalEquidistant’, ‘Sinusoidal’, ‘UTM’, ‘NearsidePerspective’, ‘LambertAzimuthalEqualArea’

Examples

This will create a Mollweide projection using Mollweide default values and annotate it with coastlines

>>> import yt
>>> ds = yt.load("")
>>> p = yt.SlicePlot(ds, "altitude", "AIRDENS")
>>> p.set_mpl_projection("AIRDENS", "Mollweide")
>>> p._setup_plots()
>>> p.plots["AIRDENS"].axes.coastlines()
>>> p.show()


This will move the PlateCarree central longitude to 90 degrees and annotate with coastlines.

>>> import yt
>>> ds = yt.load("")
>>> p = yt.SlicePlot(ds, "altitude", "AIRDENS")
>>> p.set_mpl_projection(
...     "AIRDENS", ("PlateCarree", (), {"central_longitude": 90, "globe": None})
... )
>>> p._setup_plots()
>>> p.plots["AIRDENS"].axes.set_global()
>>> p.plots["AIRDENS"].axes.coastlines()
>>> p.show()


This will create a RoatatedPole projection with the unrotated pole position at 37.5 degrees latitude and 177.5 degrees longitude by passing them in as args.

>>> import yt
>>> ds = yt.load("")
>>> p = yt.SlicePlot(ds, "altitude", "AIRDENS")
>>> p.set_mpl_projection("RotatedPole", (177.5, 37.5))
>>> p._setup_plots()
>>> p.plots["AIRDENS"].axes.set_global()
>>> p.plots["AIRDENS"].axes.coastlines()
>>> p.show()


This will create a RoatatedPole projection with the unrotated pole position at 37.5 degrees latitude and 177.5 degrees longitude by passing them in as kwargs.

>>> import yt
>>> ds = yt.load("")
>>> p = yt.SlicePlot(ds, "altitude", "AIRDENS")
>>> p.set_mpl_projection(
...     ("RotatedPole", (), {"pole_latitude": 37.5, "pole_longitude": 177.5})
... )
>>> p._setup_plots()
>>> p.plots["AIRDENS"].axes.set_global()
>>> p.plots["AIRDENS"].axes.coastlines()
>>> p.show()

set_origin(origin)

Set the plot origin.

Parameters
• origin (string or length 1, 2, or 3 sequence.) – The location of the origin of the plot coordinate system. This is typically represented by a ‘-‘ separated string or a tuple of strings. In the first index the y-location is given by ‘lower’, ‘upper’, or ‘center’. The second index is the x-location, given as ‘left’, ‘right’, or ‘center’. Finally, whether the origin is applied in ‘domain’ space, plot ‘window’ space or ‘native’ simulation coordinate system is given. For example, both ‘upper-right-domain’ and [‘upper’, ‘right’, ‘domain’] place the origin in the upper right hand corner of domain space. If x or y are not given, a value is inferred. For instance, ‘left-domain’ corresponds to the lower-left hand corner of the simulation domain, ‘center-domain’ corresponds to the center of the simulation domain, or ‘center-window’ for the center of the plot window. In the event that none of these options place the origin in a desired location, a sequence of tuples and a string specifying the coordinate space can be given. If plain numeric types are input, units of code_length are assumed. Further examples:

• =============================== (===============================================) –

• example (format) –

• ===============================

• 'domain' ('{space}') –

• 'left-window' ('{xloc}-{space}') –

• 'upper-domain' ('{yloc}-{space}') –

• 'lower-right-window' ('{yloc}-{xloc}-{space}') –

• ('window',) (('{space}',)) –

• '{space}') ('right', 'domain') (('{xloc}',) –

• '{space}') ('lower', 'window') (('{yloc}',) –

• '{xloc}', '{space}') ('lower', 'right', 'window') (('{yloc}',) –

• '{unit}'), (xloc, '{unit}'), '{space}') ((0, 'm'), (4, 'm'), 'window') (((yloc,) –

• yloc, '{space}') (0.23, 0.5, 'domain') ((xloc,) –

• ===============================

set_transform(field, name)
set_unit(field, new_unit, equivalency=None, equivalency_kwargs=None)

Sets a new unit for the requested field

Parameters
• field (string or field tuple) – The name of the field that is to be changed.

• new_unit (string or Unit object) – The name of the new unit.

• equivalency (string, optional) – If set, the equivalency to use to convert the current units to the new requested unit. If None, the unit conversion will be done without an equivalency

• equivalency_kwargs (string, optional) – Keyword arguments to be passed to the equivalency. Only used if equivalency is set.

set_width(width, unit=None)

set the width of the plot window

Parameters
• width (float, array of floats, (float, unit) tuple, or tuple of) –

(float, unit) tuples.

Width can have four different formats to support windows with variable x and y widths. They are:

format

example

(float, string)

(10,’kpc’)

((float, string), (float, string))

((10,’kpc’),(15,’kpc’))

float

0.2

(float, float)

(0.2, 0.3)

For example, (10, ‘kpc’) requests a plot window that is 10 kiloparsecs wide in the x and y directions, ((10,’kpc’),(15,’kpc’)) requests a window that is 10 kiloparsecs wide along the x axis and 15 kiloparsecs wide along the y axis. In the other two examples, code units are assumed, for example (0.2, 0.3) requests a plot that has an x width of 0.2 and a y width of 0.3 in code units. If units are provided the resulting plot axis labels will use the supplied units.

• unit (str) – the unit the width has been specified in. If width is a tuple, this argument is ignored. Defaults to code units.

set_window_size(size)

This calls set_figure_size to adjust the size of the plot window.

set_xlabel(label)

Allow the user to modify the X-axis title Defaults to the global value. Fontsize defaults to 18.

Parameters
• label (str) – The new string for the x-axis.

• plot.set_xlabel("H2I Number Density (cm$^{-3}$)") (>>>) –

set_ylabel(label)

Allow the user to modify the Y-axis title Defaults to the global value.

Parameters
• label (str) – The new string for the y-axis.

• plot.set_ylabel("Temperature (K)") (>>>) –

set_zlim(field, zmin, zmax, dynamic_range=None)

set the scale of the colormap

Parameters
• field (string) – the field to set a colormap scale if field == ‘all’, applies to all plots.

• zmin (float, tuple, YTQuantity or str) – the new minimum of the colormap scale. If ‘min’, will set to the minimum value in the current view.

• zmax (float, tuple, YTQuantity or str) – the new maximum of the colormap scale. If ‘max’, will set to the maximum value in the current view.

Other Parameters

dynamic_range (float (default: None)) – The dynamic range of the image. If zmin == None, will set zmin = zmax / dynamic_range If zmax == None, will set zmax = zmin * dynamic_range When dynamic_range is specified, defaults to setting zmin = zmax / dynamic_range.

setup_callbacks()
setup_defaults()
show()

This will send any existing plots to the IPython notebook.

If yt is being run from within an IPython session, and it is able to determine this, this function will send any existing plots to the notebook for display.

If yt can’t determine if it’s inside an IPython session, it will raise YTNotInsideNotebook.

Examples

>>> from yt.mods import SlicePlot
>>> slc = SlicePlot(
...     ds, "x", [("gas", "density"), ("gas", "velocity_magnitude")]
... )
>>> slc.show()

show_axes(field=None)

Shows the axes for a plot and updates the size of the plot accordingly. Defaults to operating on all fields for a PlotContainer object. See hide_axes().

Parameters

field (string, field tuple, or list of strings or field tuples (optional)) – The name of the field(s) that we want to show the axes.

show_colorbar(field=None)

Shows the colorbar for a plot and updates the size of the plot accordingly. Defaults to operating on all fields for a PlotContainer object. See hide_colorbar().

Parameters
• field (string, field tuple, or list of strings or field tuples (optional)) –

• name of the field(s) that we want to show the colorbar. (The) –

to_fits_data(fields=None, other_keys=None, length_unit=None, **kwargs)

Export the fields in this PlotWindow instance to a FITSImageData instance.

This will export a set of FITS images of either the fields specified or all the fields already in the object.

Parameters
• fields (list of strings) – These fields will be pixelized and output. If “None”, the keys of the FRB will be used.

• other_keys (dictionary, optional) – A set of header keys and values to write into the FITS header.

• length_unit (string, optional) – the length units that the coordinates are written in. The default is to use the default length unit of the dataset.

toggle_right_handed()
property width
zoom(factor)

This zooms the window by factor > 0. - zoom out with factor < 1 - zoom in with factor > 1

Parameters

factor (float) – multiplier for the current width

class yt.visualization.plot_window.OffAxisProjectionDummyDataSource(center, ds, normal_vector, width, fields, interpolated, weight=None, volume=None, no_ghost=False, le=None, re=None, north_vector=None, method='integrate', data_source=None)[source]

Bases: object

class yt.visualization.plot_window.OffAxisProjectionPlot(ds, normal, fields, center='c', width=None, depth=1, '1', axes_unit=None, weight_field=None, max_level=None, north_vector=None, right_handed=True, volume=None, no_ghost=False, le=None, re=None, interpolated=False, fontsize=18, method='integrate', data_source=None, buff_size=800, 800)[source]

Creates an off axis projection plot from a dataset

Given a ds object, a normal vector to project along, and a field name string, this will return a PWViewerMPL object containing the plot.

The plot can be updated using one of the many helper functions defined in PlotWindow.

Parameters
• ds (yt.data_objects.static_output.Dataset) – This is the dataset object corresponding to the simulation output to be plotted.

• normal (a sequence of floats) – The vector normal to the slicing plane.

• fields (string) – The name of the field(s) to be plotted.

• center (A sequence of floats, a string, or a tuple.) – The coordinate of the center of the image. If set to ‘c’, ‘center’ or left blank, the plot is centered on the middle of the domain. If set to ‘max’ or ‘m’, the center will be located at the maximum of the (‘gas’, ‘density’) field. Centering on the max or min of a specific field is supported by providing a tuple such as (“min”,”temperature”) or (“max”,”dark_matter_density”). Units can be specified by passing in center as a tuple containing a coordinate and string unit name or by passing in a YTArray. If a list or unitless array is supplied, code units are assumed.

• width (tuple or a float.) –

Width can have four different formats to support windows with variable x and y widths. They are:

format

example

(float, string)

(10,’kpc’)

((float, string), (float, string))

((10,’kpc’),(15,’kpc’))

float

0.2

(float, float)

(0.2, 0.3)

For example, (10, ‘kpc’) requests a plot window that is 10 kiloparsecs wide in the x and y directions, ((10,’kpc’),(15,’kpc’)) requests a window that is 10 kiloparsecs wide along the x axis and 15 kiloparsecs wide along the y axis. In the other two examples, code units are assumed, for example (0.2, 0.3) requests a plot that has an x width of 0.2 and a y width of 0.3 in code units. If units are provided the resulting plot axis labels will use the supplied units.

• depth (A tuple or a float) – A tuple containing the depth to project through and the string key of the unit: (width, ‘unit’). If set to a float, code units are assumed

• weight_field (string) – The name of the weighting field. Set to None for no weight.

• max_level (int) – The maximum level to project to.

• axes_unit (string) – The name of the unit for the tick labels on the x and y axes. Defaults to None, which automatically picks an appropriate unit. If axes_unit is ‘1’, ‘u’, or ‘unitary’, it will not display the units, and only show the axes name.

• north_vector (a sequence of floats) – A vector defining the ‘up’ direction in the plot. This option sets the orientation of the slicing plane. If not set, an arbitrary grid-aligned north-vector is chosen.

• right_handed (boolean) – Whether the implicit east vector for the image generated is set to make a right handed coordinate system with the north vector and the normal, the direction of the ‘window’ into the data.

• fontsize (integer) – The size of the fonts for the axis, colorbar, and tick labels.

• method (string) –

The method of projection. Valid methods are:

”integrate” with no weight_field specified : integrate the requested field along the line of sight.

”integrate” with a weight_field specified : weight the requested field by the weighting field and integrate along the line of sight.

”sum” : This method is the same as integrate, except that it does not multiply by a path length when performing the integration, and is just a straight summation of the field along the given axis. WARNING: This should only be used for uniform resolution grid datasets, as other datasets may result in unphysical images.

• data_source (YTSelectionContainer object) – Object to be used for data selection. Defaults to ds.all_data(), a region covering the full domain

• buff_size (length 2 sequence) – Size of the buffer to use for the image, i.e. the number of resolution elements used. Effectively sets a resolution limit to the image if buff_size is smaller than the finest gridding.

annotate_clear(index=None)

Clear callbacks from the plot. If index is not set, clear all callbacks. If index is set, clear that index (ie 0 is the first one created, 1 is the 2nd one created, -1 is the last one created, etc.)

Note

Deprecated in favor of clear_annotations.

property bounds
clear_annotations(index=None)

Clear callbacks from the plot. If index is not set, clear all callbacks. If index is set, clear that index (ie 0 is the first one created, 1 is the 2nd one created, -1 is the last one created, etc.)

display(name=None, mpl_kwargs=None)

Will attempt to show the plot in in an IPython notebook. Failing that, the plot will be saved to disk.

export_to_mpl_figure(nrows_ncols, axes_pad=1.0, label_mode='L', cbar_location='right', cbar_size='5%', cbar_mode='each', cbar_pad='0%')

Creates a matplotlib figure object with the specified axes arrangement, nrows_ncols, and maps the underlying figures to the matplotlib axes. Note that all of these parameters are fed directly to the matplotlib ImageGrid class to create the new figure layout.

Parameters
• nrows_ncols (tuple) – the number of rows and columns of the axis grid (e.g., nrows_ncols=(2,2,))

• axes_pad (float) – padding between axes in inches

• label_mode (one of "L", "1", "all") – arrangement of axes that are labeled

• cbar_location (one of "left", "right", "bottom", "top") – where to place the colorbar

• cbar_size (string (percentage)) – scaling of the colorbar (e.g., “5%”)

• cbar_mode (one of "each", "single", "edge", None) – how to represent the colorbar

• cbar_pad (string (percentage)) – padding between the axis and colorbar (e.g. “5%”)

Returns

Return type

The return is a matplotlib figure object.

Examples

>>> import yt
>>> ds = yt.load_sample("IsolatedGalaxy")
>>> fields = ["density", "velocity_x", "velocity_y", "velocity_magnitude"]
>>> p = yt.SlicePlot(ds, "z", fields)
>>> p.set_log("velocity_x", False)
>>> p.set_log("velocity_y", False)
>>> fig = p.export_to_mpl_figure((2, 2))
>>> fig.tight_layout()
>>> fig.savefig("test.png")

property frb

The frb property.

get_log(field)

get the transform type of a field.

Parameters

field (string) – the field to get a transform if field == ‘all’, applies to all plots.

hide_axes(field=None, draw_frame=False)

Hides the axes for a plot and updates the size of the plot accordingly. Defaults to operating on all fields for a PlotContainer object.

Parameters
• field (string, field tuple, or list of strings or field tuples (optional)) – The name of the field(s) that we want to hide the axes.

• draw_frame (boolean) – If True, the axes frame will still be drawn. Defaults to False. See note below for more details.

Examples

This will save an image with no axes.

>>> import yt
>>> ds = yt.load("IsolatedGalaxy/galaxy0030/galaxy0030")
>>> s = SlicePlot(ds, 2, "density", "c", (20, "kpc"))
>>> s.hide_axes()
>>> s.save()


This will save an image with no axis or colorbar.

>>> import yt
>>> ds = yt.load("IsolatedGalaxy/galaxy0030/galaxy0030")
>>> s = SlicePlot(ds, 2, "density", "c", (20, "kpc"))
>>> s.hide_axes()
>>> s.hide_colorbar()
>>> s.save()


Note

By default, when removing the axes, the patch on which the axes are drawn is disabled, making it impossible to later change e.g. the background colour. To force the axes patch to be displayed while still hiding the axes, set the draw_frame keyword argument to True.

hide_colorbar(field=None)

Hides the colorbar for a plot and updates the size of the plot accordingly. Defaults to operating on all fields for a PlotContainer object.

Parameters

field (string, field tuple, or list of strings or field tuples (optional)) – The name of the field(s) that we want to hide the colorbar. If None or ‘all’ is provided, will default to using all fields available for this object.

Examples

This will save an image with no colorbar.

>>> import yt
>>> ds = yt.load("IsolatedGalaxy/galaxy0030/galaxy0030")
>>> s = SlicePlot(ds, 2, "density", "c", (20, "kpc"))
>>> s.hide_colorbar()
>>> s.save()


This will save an image with no axis or colorbar.

>>> import yt
>>> ds = yt.load("IsolatedGalaxy/galaxy0030/galaxy0030")
>>> s = SlicePlot(ds, 2, "density", "c", (20, "kpc"))
>>> s.hide_axes()
>>> s.hide_colorbar()
>>> s.save()

list_annotations()

List the current callbacks for the plot, along with their index. This index can be used with clear_annotations to remove a callback from the current plot.

pan(deltas)

Pan the image by specifying absolute code unit coordinate deltas.

Parameters

deltas (Two-element sequence of floats, quantities, or (float, unit)) –

tuples.

(delta_x, delta_y). If a unit is not supplied the unit is assumed to be code_length.

pan_rel(deltas)

Pan the image by specifying relative deltas, to the FOV.

Parameters

deltas (sequence of floats) – (delta_x, delta_y) in relative code unit coordinates

piter(*args, **kwargs)
refresh()
run_callbacks()
save(name=None, suffix='.png', mpl_kwargs=None)

saves the plot to disk.

Parameters
• name (string or tuple) – The base of the filename. If name is a directory or if name is not set, the filename of the dataset is used. For a tuple, the resulting path will be given by joining the elements of the tuple

• suffix (string) – Specify the image type by its suffix. If not specified, the output type will be inferred from the filename. Defaults to PNG.

• mpl_kwargs (dict) – A dict of keyword arguments to be passed to matplotlib.

• slc.save(mpl_kwargs={"bbox_inches" (>>>) –

set_antialias(aa)

Turn antialiasing on or off.

Parameters

aa (boolean) –

set_axes_unit(unit_name)

Set the unit for display on the x and y axes of the image.

Parameters

unit_name (string or two element tuple of strings) – A unit, available for conversion in the dataset, that the image extents will be displayed in. If set to None, any previous units will be reset. If the unit is None, the default is chosen. If unit_name is ‘1’, ‘u’, or ‘unitary’, it will not display the units, and only show the axes name. If unit_name is a tuple, the first element is assumed to be the unit for the x axis and the second element the unit for the y axis.

Raises

YTUnitNotRecognized – If the unit is not known, this will be raised.

Examples

>>> from yt import load
>>> ds = load("IsolatedGalaxy/galaxy0030/galaxy0030")
>>> p = ProjectionPlot(ds, "y", "Density")
>>> p.set_axes_unit("kpc")

set_background_color(field, color=None)

set the background color to match provided color

Parameters
• field (string) – the field to set the colormap if field == ‘all’, applies to all plots.

• color (string or RGBA tuple (optional)) – if set, set the background color to this color if unset, background color is set to the bottom value of the color map

set_buff_size(size)

Sets a new buffer size for the fixed resolution buffer

Parameters

size (int or two element sequence of ints) – The number of data elements in the buffer on the x and y axes. If a scalar is provided, then the buffer is assumed to be square.

set_cbar_minorticks(field, state)

turn colorbar minor ticks “on” or “off” in the current plot, following state

Parameters
• field (string) – the field to remove colorbar minorticks

• state (string) – the state indicating ‘on’ or ‘off’

set_center(new_center, unit='code_length')

Sets a new center for the plot window

Parameters
• new_center (two element sequence of floats) – The coordinates of the new center of the image in the coordinate system defined by the plot axes. If the unit keyword is not specified, the coordinates are assumed to be in code units.

• unit (string) – The name of the unit new_center is given in. If new_center is a YTArray or tuple of YTQuantities, this keyword is ignored.

set_cmap(field, cmap)

set the colormap for one of the fields

Parameters
• field (string) – the field to set the colormap if field == ‘all’, applies to all plots.

• cmap (string or tuple) – If a string, will be interpreted as name of the colormap. If a tuple, it is assumed to be of the form (name, type, number) to be used for palettable functionality. (name, type, number, bool) can be used to specify if a reverse colormap is to be used.

set_colorbar_label(field, label)

Sets the colorbar label.

Parameters
• field (str or tuple) – The name of the field to modify the label for.

• label (str) – The new label

• plot.set_colorbar_label( (>>>) –

• ("gas", "density"), "Dark Matter Density (g cm$^{-3}$)" (..) –

• ) (..) –

set_colorbar_minorticks(field, state)

turn colorbar minor ticks on or off in the current plot

Displaying minor ticks reduces performance; turn them off using set_colorbar_minorticks(‘all’, False) if drawing speed is a problem.

Parameters
• field (string) – the field to remove colorbar minorticks if field == ‘all’, applies to all plots.

• state (bool) – the state indicating ‘on’ (True) or ‘off’ (False)

set_figure_size(size)

Sets a new figure size for the plot

Parameters

size (float) – The size of the figure on the longest axis (in units of inches), including the margins but not the colorbar.

set_font(font_dict=None)

Set the font and font properties.

Parameters

font_dict (dict) –

A dict of keyword parameters to be passed to matplotlib.font_manager.FontProperties.

Possible keys include:

• family - The font family. Can be serif, sans-serif, cursive, ‘fantasy’ or ‘monospace’.

• style - The font style. Either normal, italic or oblique.

• color - A valid color string like ‘r’, ‘g’, ‘red’, ‘cobalt’, and ‘orange’.

• variant - Either normal or small-caps.

• size - Either a relative value of xx-small, x-small, small, medium, large, x-large, xx-large or an absolute font size, e.g. 12

• stretch - A numeric value in the range 0-1000 or one of ultra-condensed, extra-condensed, condensed, semi-condensed, normal, semi-expanded, expanded, extra-expanded or ultra-expanded

• weight - A numeric value in the range 0-1000 or one of ultralight, light, normal, regular, book, medium, roman, semibold, demibold, demi, bold, heavy, extra bold, or black

See the matplotlib font manager API documentation for more details. https://matplotlib.org/stable/api/font_manager_api.html

Notes

Mathtext axis labels will only obey the size and color keyword.

Examples

This sets the font to be 24-pt, blue, sans-serif, italic, and bold-face.

>>> slc = SlicePlot(ds, "x", "Density")
>>> slc.set_font(
...     {
...         "family": "sans-serif",
...         "style": "italic",
...         "weight": "bold",
...         "size": 24,
...         "color": "blue",
...     }
... )

set_font_size(size)

Set the size of the font used in the plot

This sets the font size by calling the set_font function. See set_font for more font customization options.

Parameters
• size (float) –

• absolute size of the font in points (1 pt = 1/72 inch) (The) –

set_log(field, log, linthresh=None, symlog_auto=False)

set a field to log, linear, or symlog.

Symlog scaling is a combination of linear and log, where from 0 to a threshold value, it operates as linear, and then beyond that it operates as log. Symlog can also work with negative values in log space as well as negative and positive values simultaneously and symmetrically. If symlog scaling is desired, please set log=True and either set symlog_auto=True or select a alue for linthresh.

Parameters
• field (string) – the field to set a transform if field == ‘all’, applies to all plots.

• log (boolean) – Log on/off: on means log scaling; off means linear scaling. Unless a linthresh is set or symlog_auto is set in which case symlog is used.

• linthresh (float, optional) – when using symlog scaling, linthresh is the value at which scaling transitions from linear to logarithmic. linthresh must be positive. Note: setting linthresh will automatically enable symlog scale

• symlog_auto (boolean) – if symlog_auto is True, then yt will use symlog scaling and attempt to determine a linthresh automatically. Setting a linthresh manually overrides this value.

set_minorticks(field, state)

Turn minor ticks on or off in the current plot.

Displaying minor ticks reduces performance; turn them off using set_minorticks(‘all’, False) if drawing speed is a problem.

Parameters
• field (string) – the field to remove minorticks if field == ‘all’, applies to all plots.

• state (bool) – the state indicating ‘on’ (True) or ‘off’ (False)

set_mpl_projection(mpl_proj)

Set the matplotlib projection type with a cartopy transform function

Given a string or a tuple argument, this will project the data onto the plot axes with the chosen transform function.

Assumes that the underlying data has a PlateCarree transform type.

To annotate the plot with coastlines or other annotations, _setup_plots() will need to be called after this function to make the axes available for annotation.

Parameters

mpl_proj (string or tuple) – if passed as a string, mpl_proj is the specified projection type, if passed as a tuple, then tuple will take the form of ("ProjectionType", (args)) or ("ProjectionType", (args), {kwargs}) Valid projection type options include: ‘PlateCarree’, ‘LambertConformal’, ‘LabmbertCylindrical’, ‘Mercator’, ‘Miller’, ‘Mollweide’, ‘Orthographic’, ‘Robinson’, ‘Stereographic’, ‘TransverseMercator’, ‘InterruptedGoodeHomolosine’, ‘RotatedPole’, ‘OGSB’, ‘EuroPP’, ‘Geostationary’, ‘Gnomonic’, ‘NorthPolarStereo’, ‘OSNI’, ‘SouthPolarStereo’, ‘AlbersEqualArea’, ‘AzimuthalEquidistant’, ‘Sinusoidal’, ‘UTM’, ‘NearsidePerspective’, ‘LambertAzimuthalEqualArea’

Examples

This will create a Mollweide projection using Mollweide default values and annotate it with coastlines

>>> import yt
>>> ds = yt.load("")
>>> p = yt.SlicePlot(ds, "altitude", "AIRDENS")
>>> p.set_mpl_projection("AIRDENS", "Mollweide")
>>> p._setup_plots()
>>> p.plots["AIRDENS"].axes.coastlines()
>>> p.show()


This will move the PlateCarree central longitude to 90 degrees and annotate with coastlines.

>>> import yt
>>> ds = yt.load("")
>>> p = yt.SlicePlot(ds, "altitude", "AIRDENS")
>>> p.set_mpl_projection(
...     "AIRDENS", ("PlateCarree", (), {"central_longitude": 90, "globe": None})
... )
>>> p._setup_plots()
>>> p.plots["AIRDENS"].axes.set_global()
>>> p.plots["AIRDENS"].axes.coastlines()
>>> p.show()


This will create a RoatatedPole projection with the unrotated pole position at 37.5 degrees latitude and 177.5 degrees longitude by passing them in as args.

>>> import yt
>>> ds = yt.load("")
>>> p = yt.SlicePlot(ds, "altitude", "AIRDENS")
>>> p.set_mpl_projection("RotatedPole", (177.5, 37.5))
>>> p._setup_plots()
>>> p.plots["AIRDENS"].axes.set_global()
>>> p.plots["AIRDENS"].axes.coastlines()
>>> p.show()


This will create a RoatatedPole projection with the unrotated pole position at 37.5 degrees latitude and 177.5 degrees longitude by passing them in as kwargs.

>>> import yt
>>> ds = yt.load("")
>>> p = yt.SlicePlot(ds, "altitude", "AIRDENS")
>>> p.set_mpl_projection(
...     ("RotatedPole", (), {"pole_latitude": 37.5, "pole_longitude": 177.5})
... )
>>> p._setup_plots()
>>> p.plots["AIRDENS"].axes.set_global()
>>> p.plots["AIRDENS"].axes.coastlines()
>>> p.show()

set_origin(origin)

Set the plot origin.

Parameters
• origin (string or length 1, 2, or 3 sequence.) – The location of the origin of the plot coordinate system. This is typically represented by a ‘-‘ separated string or a tuple of strings. In the first index the y-location is given by ‘lower’, ‘upper’, or ‘center’. The second index is the x-location, given as ‘left’, ‘right’, or ‘center’. Finally, whether the origin is applied in ‘domain’ space, plot ‘window’ space or ‘native’ simulation coordinate system is given. For example, both ‘upper-right-domain’ and [‘upper’, ‘right’, ‘domain’] place the origin in the upper right hand corner of domain space. If x or y are not given, a value is inferred. For instance, ‘left-domain’ corresponds to the lower-left hand corner of the simulation domain, ‘center-domain’ corresponds to the center of the simulation domain, or ‘center-window’ for the center of the plot window. In the event that none of these options place the origin in a desired location, a sequence of tuples and a string specifying the coordinate space can be given. If plain numeric types are input, units of code_length are assumed. Further examples:

• =============================== (===============================================) –

• example (format) –

• ===============================

• 'domain' ('{space}') –

• 'left-window' ('{xloc}-{space}') –

• 'upper-domain' ('{yloc}-{space}') –

• 'lower-right-window' ('{yloc}-{xloc}-{space}') –

• ('window',) (('{space}',)) –

• '{space}') ('right', 'domain') (('{xloc}',) –

• '{space}') ('lower', 'window') (('{yloc}',) –

• '{xloc}', '{space}') ('lower', 'right', 'window') (('{yloc}',) –

• '{unit}'), (xloc, '{unit}'), '{space}') ((0, 'm'), (4, 'm'), 'window') (((yloc,) –

• yloc, '{space}') (0.23, 0.5, 'domain') ((xloc,) –

• ===============================

set_transform(field, name)
set_unit(field, new_unit, equivalency=None, equivalency_kwargs=None)

Sets a new unit for the requested field

Parameters
• field (string or field tuple) – The name of the field that is to be changed.

• new_unit (string or Unit object) – The name of the new unit.

• equivalency (string, optional) – If set, the equivalency to use to convert the current units to the new requested unit. If None, the unit conversion will be done without an equivalency

• equivalency_kwargs (string, optional) – Keyword arguments to be passed to the equivalency. Only used if equivalency is set.

set_width(width, unit=None)

set the width of the plot window

Parameters
• width (float, array of floats, (float, unit) tuple, or tuple of) –

(float, unit) tuples.

Width can have four different formats to support windows with variable x and y widths. They are:

format

example

(float, string)

(10,’kpc’)

((float, string), (float, string))

((10,’kpc’),(15,’kpc’))

float

0.2

(float, float)

(0.2, 0.3)

For example, (10, ‘kpc’) requests a plot window that is 10 kiloparsecs wide in the x and y directions, ((10,’kpc’),(15,’kpc’)) requests a window that is 10 kiloparsecs wide along the x axis and 15 kiloparsecs wide along the y axis. In the other two examples, code units are assumed, for example (0.2, 0.3) requests a plot that has an x width of 0.2 and a y width of 0.3 in code units. If units are provided the resulting plot axis labels will use the supplied units.

• unit (str) – the unit the width has been specified in. If width is a tuple, this argument is ignored. Defaults to code units.

set_window_size(size)

This calls set_figure_size to adjust the size of the plot window.

set_xlabel(label)

Allow the user to modify the X-axis title Defaults to the global value. Fontsize defaults to 18.

Parameters
• label (str) – The new string for the x-axis.

• plot.set_xlabel("H2I Number Density (cm$^{-3}$)") (>>>) –

set_ylabel(label)

Allow the user to modify the Y-axis title Defaults to the global value.

Parameters
• label (str) – The new string for the y-axis.

• plot.set_ylabel("Temperature (K)") (>>>) –

set_zlim(field, zmin, zmax, dynamic_range=None)

set the scale of the colormap

Parameters
• field (string) – the field to set a colormap scale if field == ‘all’, applies to all plots.

• zmin (float, tuple, YTQuantity or str) – the new minimum of the colormap scale. If ‘min’, will set to the minimum value in the current view.

• zmax (float, tuple, YTQuantity or str) – the new maximum of the colormap scale. If ‘max’, will set to the maximum value in the current view.

Other Parameters

dynamic_range (float (default: None)) – The dynamic range of the image. If zmin == None, will set zmin = zmax / dynamic_range If zmax == None, will set zmax = zmin * dynamic_range When dynamic_range is specified, defaults to setting zmin = zmax / dynamic_range.

setup_callbacks()
setup_defaults()
show()

This will send any existing plots to the IPython notebook.

If yt is being run from within an IPython session, and it is able to determine this, this function will send any existing plots to the notebook for display.

If yt can’t determine if it’s inside an IPython session, it will raise YTNotInsideNotebook.

Examples

>>> from yt.mods import SlicePlot
>>> slc = SlicePlot(
...     ds, "x", [("gas", "density"), ("gas", "velocity_magnitude")]
... )
>>> slc.show()

show_axes(field=None)

Shows the axes for a plot and updates the size of the plot accordingly. Defaults to operating on all fields for a PlotContainer object. See hide_axes().

Parameters

field (string, field tuple, or list of strings or field tuples (optional)) – The name of the field(s) that we want to show the axes.

show_colorbar(field=None)

Shows the colorbar for a plot and updates the size of the plot accordingly. Defaults to operating on all fields for a PlotContainer object. See hide_colorbar().

Parameters
• field (string, field tuple, or list of strings or field tuples (optional)) –

• name of the field(s) that we want to show the colorbar. (The) –

to_fits_data(fields=None, other_keys=None, length_unit=None, **kwargs)

Export the fields in this PlotWindow instance to a FITSImageData instance.

This will export a set of FITS images of either the fields specified or all the fields already in the object.

Parameters
• fields (list of strings) – These fields will be pixelized and output. If “None”, the keys of the FRB will be used.

• other_keys (dictionary, optional) – A set of header keys and values to write into the FITS header.

• length_unit (string, optional) – the length units that the coordinates are written in. The default is to use the default length unit of the dataset.

toggle_right_handed()
property width
zoom(factor)

This zooms the window by factor > 0. - zoom out with factor < 1 - zoom in with factor > 1

Parameters

factor (float) – multiplier for the current width

class yt.visualization.plot_window.OffAxisSlicePlot(ds, normal, fields, center='c', width=None, axes_unit=None, north_vector=None, right_handed=True, fontsize=18, field_parameters=None, data_source=None, buff_size=800, 800)[source]

Creates an off axis slice plot from a dataset

Given a ds object, a normal vector defining a slicing plane, and a field name string, this will return a PWViewerMPL object containing the plot.

The plot can be updated using one of the many helper functions defined in PlotWindow.

Parameters
• ds (yt.data_objects.static_output.Dataset) – This is the dataset object corresponding to the simulation output to be plotted.

• normal (a sequence of floats) – The vector normal to the slicing plane.

• fields (string) – The name of the field(s) to be plotted.

• center (A sequence of floats, a string, or a tuple.) – The coordinate of the center of the image. If set to ‘c’, ‘center’ or left blank, the plot is centered on the middle of the domain. If set to ‘max’ or ‘m’, the center will be located at the maximum of the (‘gas’, ‘density’) field. Centering on the max or min of a specific field is supported by providing a tuple such as (“min”,”temperature”) or (“max”,”dark_matter_density”). Units can be specified by passing in center as a tuple containing a coordinate and string unit name or by passing in a YTArray. If a list or unitless array is supplied, code units are assumed.

• width (tuple or a float.) –

Width can have four different formats to support windows with variable x and y widths. They are:

format

example

(float, string)

(10,’kpc’)

((float, string), (float, string))

((10,’kpc’),(15,’kpc’))

float

0.2

(float, float)

(0.2, 0.3)

For example, (10, ‘kpc’) requests a plot window that is 10 kiloparsecs wide in the x and y directions, ((10,’kpc’),(15,’kpc’)) requests a window that is 10 kiloparsecs wide along the x axis and 15 kiloparsecs wide along the y axis. In the other two examples, code units are assumed, for example (0.2, 0.3) requests a plot that has an x width of 0.2 and a y width of 0.3 in code units. If units are provided the resulting plot axis labels will use the supplied units.

• axes_unit (string) – The name of the unit for the tick labels on the x and y axes. Defaults to None, which automatically picks an appropriate unit. If axes_unit is ‘1’, ‘u’, or ‘unitary’, it will not display the units, and only show the axes name.

• north_vector (a sequence of floats) – A vector defining the ‘up’ direction in the plot. This option sets the orientation of the slicing plane. If not set, an arbitrary grid-aligned north-vector is chosen.

• right_handed (boolean) – Whether the implicit east vector for the image generated is set to make a right handed coordinate system with the north vector and the normal, the direction of the ‘window’ into the data.

• fontsize (integer) – The size of the fonts for the axis, colorbar, and tick labels.

• field_parameters (dictionary) – A dictionary of field parameters than can be accessed by derived fields.

• data_source (YTSelectionContainer Object) – Object to be used for data selection. Defaults ds.all_data(), a region covering the full domain.

• buff_size (length 2 sequence) – Size of the buffer to use for the image, i.e. the number of resolution elements used. Effectively sets a resolution limit to the image if buff_size is smaller than the finest gridding.

annotate_clear(index=None)

Clear callbacks from the plot. If index is not set, clear all callbacks. If index is set, clear that index (ie 0 is the first one created, 1 is the 2nd one created, -1 is the last one created, etc.)

Note

Deprecated in favor of clear_annotations.

property bounds
clear_annotations(index=None)

Clear callbacks from the plot. If index is not set, clear all callbacks. If index is set, clear that index (ie 0 is the first one created, 1 is the 2nd one created, -1 is the last one created, etc.)

display(name=None, mpl_kwargs=None)

Will attempt to show the plot in in an IPython notebook. Failing that, the plot will be saved to disk.

export_to_mpl_figure(nrows_ncols, axes_pad=1.0, label_mode='L', cbar_location='right', cbar_size='5%', cbar_mode='each', cbar_pad='0%')

Creates a matplotlib figure object with the specified axes arrangement, nrows_ncols, and maps the underlying figures to the matplotlib axes. Note that all of these parameters are fed directly to the matplotlib ImageGrid class to create the new figure layout.

Parameters
• nrows_ncols (tuple) – the number of rows and columns of the axis grid (e.g., nrows_ncols=(2,2,))

• axes_pad (float) – padding between axes in inches

• label_mode (one of "L", "1", "all") – arrangement of axes that are labeled

• cbar_location (one of "left", "right", "bottom", "top") – where to place the colorbar

• cbar_size (string (percentage)) – scaling of the colorbar (e.g., “5%”)

• cbar_mode (one of "each", "single", "edge", None) – how to represent the colorbar

• cbar_pad (string (percentage)) – padding between the axis and colorbar (e.g. “5%”)

Returns

Return type

The return is a matplotlib figure object.

Examples

>>> import yt
>>> ds = yt.load_sample("IsolatedGalaxy")
>>> fields = ["density", "velocity_x", "velocity_y", "velocity_magnitude"]
>>> p = yt.SlicePlot(ds, "z", fields)
>>> p.set_log("velocity_x", False)
>>> p.set_log("velocity_y", False)
>>> fig = p.export_to_mpl_figure((2, 2))
>>> fig.tight_layout()
>>> fig.savefig("test.png")

property frb

The frb property.

get_log(field)

get the transform type of a field.

Parameters

field (string) – the field to get a transform if field == ‘all’, applies to all plots.

hide_axes(field=None, draw_frame=False)

Hides the axes for a plot and updates the size of the plot accordingly. Defaults to operating on all fields for a PlotContainer object.

Parameters
• field (string, field tuple, or list of strings or field tuples (optional)) – The name of the field(s) that we want to hide the axes.

• draw_frame (boolean) – If True, the axes frame will still be drawn. Defaults to False. See note below for more details.

Examples

This will save an image with no axes.

>>> import yt
>>> ds = yt.load("IsolatedGalaxy/galaxy0030/galaxy0030")
>>> s = SlicePlot(ds, 2, "density", "c", (20, "kpc"))
>>> s.hide_axes()
>>> s.save()


This will save an image with no axis or colorbar.

>>> import yt
>>> ds = yt.load("IsolatedGalaxy/galaxy0030/galaxy0030")
>>> s = SlicePlot(ds, 2, "density", "c", (20, "kpc"))
>>> s.hide_axes()
>>> s.hide_colorbar()
>>> s.save()


Note

By default, when removing the axes, the patch on which the axes are drawn is disabled, making it impossible to later change e.g. the background colour. To force the axes patch to be displayed while still hiding the axes, set the draw_frame keyword argument to True.

hide_colorbar(field=None)

Hides the colorbar for a plot and updates the size of the plot accordingly. Defaults to operating on all fields for a PlotContainer object.

Parameters

field (string, field tuple, or list of strings or field tuples (optional)) – The name of the field(s) that we want to hide the colorbar. If None or ‘all’ is provided, will default to using all fields available for this object.

Examples

This will save an image with no colorbar.

>>> import yt
>>> ds = yt.load("IsolatedGalaxy/galaxy0030/galaxy0030")
>>> s = SlicePlot(ds, 2, "density", "c", (20, "kpc"))
>>> s.hide_colorbar()
>>> s.save()


This will save an image with no axis or colorbar.

>>> import yt
>>> ds = yt.load("IsolatedGalaxy/galaxy0030/galaxy0030")
>>> s = SlicePlot(ds, 2, "density", "c", (20, "kpc"))
>>> s.hide_axes()
>>> s.hide_colorbar()
>>> s.save()

list_annotations()

List the current callbacks for the plot, along with their index. This index can be used with clear_annotations to remove a callback from the current plot.

pan(deltas)

Pan the image by specifying absolute code unit coordinate deltas.

Parameters

deltas (Two-element sequence of floats, quantities, or (float, unit)) –

tuples.

(delta_x, delta_y). If a unit is not supplied the unit is assumed to be code_length.

pan_rel(deltas)

Pan the image by specifying relative deltas, to the FOV.

Parameters

deltas (sequence of floats) – (delta_x, delta_y) in relative code unit coordinates

piter(*args, **kwargs)
refresh()
run_callbacks()
save(name=None, suffix='.png', mpl_kwargs=None)

saves the plot to disk.

Parameters
• name (string or tuple) – The base of the filename. If name is a directory or if name is not set, the filename of the dataset is used. For a tuple, the resulting path will be given by joining the elements of the tuple

• suffix (string) – Specify the image type by its suffix. If not specified, the output type will be inferred from the filename. Defaults to PNG.

• mpl_kwargs (dict) – A dict of keyword arguments to be passed to matplotlib.

• slc.save(mpl_kwargs={"bbox_inches" (>>>) –

set_antialias(aa)

Turn antialiasing on or off.

Parameters

aa (boolean) –

set_axes_unit(unit_name)

Set the unit for display on the x and y axes of the image.

Parameters

unit_name (string or two element tuple of strings) – A unit, available for conversion in the dataset, that the image extents will be displayed in. If set to None, any previous units will be reset. If the unit is None, the default is chosen. If unit_name is ‘1’, ‘u’, or ‘unitary’, it will not display the units, and only show the axes name. If unit_name is a tuple, the first element is assumed to be the unit for the x axis and the second element the unit for the y axis.

Raises

YTUnitNotRecognized – If the unit is not known, this will be raised.

Examples

>>> from yt import load
>>> ds = load("IsolatedGalaxy/galaxy0030/galaxy0030")
>>> p = ProjectionPlot(ds, "y", "Density")
>>> p.set_axes_unit("kpc")

set_background_color(field, color=None)

set the background color to match provided color

Parameters
• field (string) – the field to set the colormap if field == ‘all’, applies to all plots.

• color (string or RGBA tuple (optional)) – if set, set the background color to this color if unset, background color is set to the bottom value of the color map

set_buff_size(size)

Sets a new buffer size for the fixed resolution buffer

Parameters

size (int or two element sequence of ints) – The number of data elements in the buffer on the x and y axes. If a scalar is provided, then the buffer is assumed to be square.

set_cbar_minorticks(field, state)

turn colorbar minor ticks “on” or “off” in the current plot, following state

Parameters
• field (string) – the field to remove colorbar minorticks

• state (string) – the state indicating ‘on’ or ‘off’

set_center(new_center, unit='code_length')

Sets a new center for the plot window

Parameters
• new_center (two element sequence of floats) – The coordinates of the new center of the image in the coordinate system defined by the plot axes. If the unit keyword is not specified, the coordinates are assumed to be in code units.

• unit (string) – The name of the unit new_center is given in. If new_center is a YTArray or tuple of YTQuantities, this keyword is ignored.

set_cmap(field, cmap)

set the colormap for one of the fields

Parameters
• field (string) – the field to set the colormap if field == ‘all’, applies to all plots.

• cmap (string or tuple) – If a string, will be interpreted as name of the colormap. If a tuple, it is assumed to be of the form (name, type, number) to be used for palettable functionality. (name, type, number, bool) can be used to specify if a reverse colormap is to be used.

set_colorbar_label(field, label)

Sets the colorbar label.

Parameters
• field (str or tuple) – The name of the field to modify the label for.

• label (str) – The new label

• plot.set_colorbar_label( (>>>) –

• ("gas", "density"), "Dark Matter Density (g cm$^{-3}$)" (..) –

• ) (..) –

set_colorbar_minorticks(field, state)

turn colorbar minor ticks on or off in the current plot

Displaying minor ticks reduces performance; turn them off using set_colorbar_minorticks(‘all’, False) if drawing speed is a problem.

Parameters
• field (string) – the field to remove colorbar minorticks if field == ‘all’, applies to all plots.

• state (bool) – the state indicating ‘on’ (True) or ‘off’ (False)

set_figure_size(size)

Sets a new figure size for the plot

Parameters

size (float) – The size of the figure on the longest axis (in units of inches), including the margins but not the colorbar.

set_font(font_dict=None)

Set the font and font properties.

Parameters

font_dict (dict) –

A dict of keyword parameters to be passed to matplotlib.font_manager.FontProperties.

Possible keys include:

• family - The font family. Can be serif, sans-serif, cursive, ‘fantasy’ or ‘monospace’.

• style - The font style. Either normal, italic or oblique.

• color - A valid color string like ‘r’, ‘g’, ‘red’, ‘cobalt’, and ‘orange’.

• variant - Either normal or small-caps.

• size - Either a relative value of xx-small, x-small, small, medium, large, x-large, xx-large or an absolute font size, e.g. 12

• stretch - A numeric value in the range 0-1000 or one of ultra-condensed, extra-condensed, condensed, semi-condensed, normal, semi-expanded, expanded, extra-expanded or ultra-expanded

• weight - A numeric value in the range 0-1000 or one of ultralight, light, normal, regular, book, medium, roman, semibold, demibold, demi, bold, heavy, extra bold, or black

See the matplotlib font manager API documentation for more details. https://matplotlib.org/stable/api/font_manager_api.html

Notes

Mathtext axis labels will only obey the size and color keyword.

Examples

This sets the font to be 24-pt, blue, sans-serif, italic, and bold-face.

>>> slc = SlicePlot(ds, "x", "Density")
>>> slc.set_font(
...     {
...         "family": "sans-serif",
...         "style": "italic",
...         "weight": "bold",
...         "size": 24,
...         "color": "blue",
...     }
... )

set_font_size(size)

Set the size of the font used in the plot

This sets the font size by calling the set_font function. See set_font for more font customization options.

Parameters
• size (float) –

• absolute size of the font in points (1 pt = 1/72 inch) (The) –

set_log(field, log, linthresh=None, symlog_auto=False)

set a field to log, linear, or symlog.

Symlog scaling is a combination of linear and log, where from 0 to a threshold value, it operates as linear, and then beyond that it operates as log. Symlog can also work with negative values in log space as well as negative and positive values simultaneously and symmetrically. If symlog scaling is desired, please set log=True and either set symlog_auto=True or select a alue for linthresh.

Parameters
• field (string) – the field to set a transform if field == ‘all’, applies to all plots.

• log (boolean) – Log on/off: on means log scaling; off means linear scaling. Unless a linthresh is set or symlog_auto is set in which case symlog is used.

• linthresh (float, optional) – when using symlog scaling, linthresh is the value at which scaling transitions from linear to logarithmic. linthresh must be positive. Note: setting linthresh will automatically enable symlog scale

• symlog_auto (boolean) – if symlog_auto is True, then yt will use symlog scaling and attempt to determine a linthresh automatically. Setting a linthresh manually overrides this value.

set_minorticks(field, state)

Turn minor ticks on or off in the current plot.

Displaying minor ticks reduces performance; turn them off using set_minorticks(‘all’, False) if drawing speed is a problem.

Parameters
• field (string) – the field to remove minorticks if field == ‘all’, applies to all plots.

• state (bool) – the state indicating ‘on’ (True) or ‘off’ (False)

set_mpl_projection(mpl_proj)

Set the matplotlib projection type with a cartopy transform function

Given a string or a tuple argument, this will project the data onto the plot axes with the chosen transform function.

Assumes that the underlying data has a PlateCarree transform type.

To annotate the plot with coastlines or other annotations, _setup_plots() will need to be called after this function to make the axes available for annotation.

Parameters

mpl_proj (string or tuple) – if passed as a string, mpl_proj is the specified projection type, if passed as a tuple, then tuple will take the form of ("ProjectionType", (args)) or ("ProjectionType", (args), {kwargs}) Valid projection type options include: ‘PlateCarree’, ‘LambertConformal’, ‘LabmbertCylindrical’, ‘Mercator’, ‘Miller’, ‘Mollweide’, ‘Orthographic’, ‘Robinson’, ‘Stereographic’, ‘TransverseMercator’, ‘InterruptedGoodeHomolosine’, ‘RotatedPole’, ‘OGSB’, ‘EuroPP’, ‘Geostationary’, ‘Gnomonic’, ‘NorthPolarStereo’, ‘OSNI’, ‘SouthPolarStereo’, ‘AlbersEqualArea’, ‘AzimuthalEquidistant’, ‘Sinusoidal’, ‘UTM’, ‘NearsidePerspective’, ‘LambertAzimuthalEqualArea’

Examples

This will create a Mollweide projection using Mollweide default values and annotate it with coastlines

>>> import yt
>>> ds = yt.load("")
>>> p = yt.SlicePlot(ds, "altitude", "AIRDENS")
>>> p.set_mpl_projection("AIRDENS", "Mollweide")
>>> p._setup_plots()
>>> p.plots["AIRDENS"].axes.coastlines()
>>> p.show()


This will move the PlateCarree central longitude to 90 degrees and annotate with coastlines.

>>> import yt
>>> ds = yt.load("")
>>> p = yt.SlicePlot(ds, "altitude", "AIRDENS")
>>> p.set_mpl_projection(
...     "AIRDENS", ("PlateCarree", (), {"central_longitude": 90, "globe": None})
... )
>>> p._setup_plots()
>>> p.plots["AIRDENS"].axes.set_global()
>>> p.plots["AIRDENS"].axes.coastlines()
>>> p.show()


This will create a RoatatedPole projection with the unrotated pole position at 37.5 degrees latitude and 177.5 degrees longitude by passing them in as args.

>>> import yt
>>> ds = yt.load("")
>>> p = yt.SlicePlot(ds, "altitude", "AIRDENS")
>>> p.set_mpl_projection("RotatedPole", (177.5, 37.5))
>>> p._setup_plots()
>>> p.plots["AIRDENS"].axes.set_global()
>>> p.plots["AIRDENS"].axes.coastlines()
>>> p.show()


This will create a RoatatedPole projection with the unrotated pole position at 37.5 degrees latitude and 177.5 degrees longitude by passing them in as kwargs.

>>> import yt
>>> ds = yt.load("")
>>> p = yt.SlicePlot(ds, "altitude", "AIRDENS")
>>> p.set_mpl_projection(
...     ("RotatedPole", (), {"pole_latitude": 37.5, "pole_longitude": 177.5})
... )
>>> p._setup_plots()
>>> p.plots["AIRDENS"].axes.set_global()
>>> p.plots["AIRDENS"].axes.coastlines()
>>> p.show()

set_origin(origin)

Set the plot origin.

Parameters
• origin (string or length 1, 2, or 3 sequence.) – The location of the origin of the plot coordinate system. This is typically represented by a ‘-‘ separated string or a tuple of strings. In the first index the y-location is given by ‘lower’, ‘upper’, or ‘center’. The second index is the x-location, given as ‘left’, ‘right’, or ‘center’. Finally, whether the origin is applied in ‘domain’ space, plot ‘window’ space or ‘native’ simulation coordinate system is given. For example, both ‘upper-right-domain’ and [‘upper’, ‘right’, ‘domain’] place the origin in the upper right hand corner of domain space. If x or y are not given, a value is inferred. For instance, ‘left-domain’ corresponds to the lower-left hand corner of the simulation domain, ‘center-domain’ corresponds to the center of the simulation domain, or ‘center-window’ for the center of the plot window. In the event that none of these options place the origin in a desired location, a sequence of tuples and a string specifying the coordinate space can be given. If plain numeric types are input, units of code_length are assumed. Further examples:

• =============================== (===============================================) –

• example (format) –

• ===============================

• 'domain' ('{space}') –

• 'left-window' ('{xloc}-{space}') –

• 'upper-domain' ('{yloc}-{space}') –

• 'lower-right-window' ('{yloc}-{xloc}-{space}') –

• ('window',) (('{space}',)) –

• '{space}') ('right', 'domain') (('{xloc}',) –

• '{space}') ('lower', 'window') (('{yloc}',) –

• '{xloc}', '{space}') ('lower', 'right', 'window') (('{yloc}',) –

• '{unit}'), (xloc, '{unit}'), '{space}') ((0, 'm'), (4, 'm'), 'window') (((yloc,) –

• yloc, '{space}') (0.23, 0.5, 'domain') ((xloc,) –

• ===============================

set_transform(field, name)
set_unit(field, new_unit, equivalency=None, equivalency_kwargs=None)

Sets a new unit for the requested field

Parameters
• field (string or field tuple) – The name of the field that is to be changed.

• new_unit (string or Unit object) – The name of the new unit.

• equivalency (string, optional) – If set, the equivalency to use to convert the current units to the new requested unit. If None, the unit conversion will be done without an equivalency

• equivalency_kwargs (string, optional) – Keyword arguments to be passed to the equivalency. Only used if equivalency is set.

set_width(width, unit=None)

set the width of the plot window

Parameters
• width (float, array of floats, (float, unit) tuple, or tuple of) –

(float, unit) tuples.

Width can have four different formats to support windows with variable x and y widths. They are:

format

example

(float, string)

(10,’kpc’)

((float, string), (float, string))

((10,’kpc’),(15,’kpc’))

float

0.2

(float, float)

(0.2, 0.3)

For example, (10, ‘kpc’) requests a plot window that is 10 kiloparsecs wide in the x and y directions, ((10,’kpc’),(15,’kpc’)) requests a window that is 10 kiloparsecs wide along the x axis and 15 kiloparsecs wide along the y axis. In the other two examples, code units are assumed, for example (0.2, 0.3) requests a plot that has an x width of 0.2 and a y width of 0.3 in code units. If units are provided the resulting plot axis labels will use the supplied units.

• unit (str) – the unit the width has been specified in. If width is a tuple, this argument is ignored. Defaults to code units.

set_window_size(size)

This calls set_figure_size to adjust the size of the plot window.

set_xlabel(label)

Allow the user to modify the X-axis title Defaults to the global value. Fontsize defaults to 18.

Parameters
• label (str) – The new string for the x-axis.

• plot.set_xlabel("H2I Number Density (cm$^{-3}$)") (>>>) –

set_ylabel(label)

Allow the user to modify the Y-axis title Defaults to the global value.

Parameters
• label (str) – The new string for the y-axis.

• plot.set_ylabel("Temperature (K)") (>>>) –

set_zlim(field, zmin, zmax, dynamic_range=None)

set the scale of the colormap

Parameters
• field (string) – the field to set a colormap scale if field == ‘all’, applies to all plots.

• zmin (float, tuple, YTQuantity or str) – the new minimum of the colormap scale. If ‘min’, will set to the minimum value in the current view.

• zmax (float, tuple, YTQuantity or str) – the new maximum of the colormap scale. If ‘max’, will set to the maximum value in the current view.

Other Parameters

dynamic_range (float (default: None)) – The dynamic range of the image. If zmin == None, will set zmin = zmax / dynamic_range If zmax == None, will set zmax = zmin * dynamic_range When dynamic_range is specified, defaults to setting zmin = zmax / dynamic_range.

setup_callbacks()
setup_defaults()
show()

This will send any existing plots to the IPython notebook.

If yt is being run from within an IPython session, and it is able to determine this, this function will send any existing plots to the notebook for display.

If yt can’t determine if it’s inside an IPython session, it will raise YTNotInsideNotebook.

Examples

>>> from yt.mods import SlicePlot
>>> slc = SlicePlot(
...     ds, "x", [("gas", "density"), ("gas", "velocity_magnitude")]
... )
>>> slc.show()

show_axes(field=None)

Shows the axes for a plot and updates the size of the plot accordingly. Defaults to operating on all fields for a PlotContainer object. See hide_axes().

Parameters

field (string, field tuple, or list of strings or field tuples (optional)) – The name of the field(s) that we want to show the axes.

show_colorbar(field=None)

Shows the colorbar for a plot and updates the size of the plot accordingly. Defaults to operating on all fields for a PlotContainer object. See hide_colorbar().

Parameters
• field (string, field tuple, or list of strings or field tuples (optional)) –

• name of the field(s) that we want to show the colorbar. (The) –

to_fits_data(fields=None, other_keys=None, length_unit=None, **kwargs)

Export the fields in this PlotWindow instance to a FITSImageData instance.

This will export a set of FITS images of either the fields specified or all the fields already in the object.

Parameters
• fields (list of strings) – These fields will be pixelized and output. If “None”, the keys of the FRB will be used.

• other_keys (dictionary, optional) – A set of header keys and values to write into the FITS header.

• length_unit (string, optional) – the length units that the coordinates are written in. The default is to use the default length unit of the dataset.

toggle_right_handed()
property width
zoom(factor)

This zooms the window by factor > 0. - zoom out with factor < 1 - zoom in with factor > 1

Parameters

factor (float) – multiplier for the current width

class yt.visualization.plot_window.PWViewerMPL(*args, **kwargs)[source]

Viewer using matplotlib as a backend via the WindowPlotMPL.

annotate_clear(index=None)[source]

Clear callbacks from the plot. If index is not set, clear all callbacks. If index is set, clear that index (ie 0 is the first one created, 1 is the 2nd one created, -1 is the last one created, etc.)

Note

Deprecated in favor of clear_annotations.

property bounds
clear_annotations(index=None)[source]

Clear callbacks from the plot. If index is not set, clear all callbacks. If index is set, clear that index (ie 0 is the first one created, 1 is the 2nd one created, -1 is the last one created, etc.)

display(name=None, mpl_kwargs=None)

Will attempt to show the plot in in an IPython notebook. Failing that, the plot will be saved to disk.

export_to_mpl_figure(nrows_ncols, axes_pad=1.0, label_mode='L', cbar_location='right', cbar_size='5%', cbar_mode='each', cbar_pad='0%')[source]

Creates a matplotlib figure object with the specified axes arrangement, nrows_ncols, and maps the underlying figures to the matplotlib axes. Note that all of these parameters are fed directly to the matplotlib ImageGrid class to create the new figure layout.

Parameters
• nrows_ncols (tuple) – the number of rows and columns of the axis grid (e.g., nrows_ncols=(2,2,))

• axes_pad (float) – padding between axes in inches

• label_mode (one of "L", "1", "all") – arrangement of axes that are labeled

• cbar_location (one of "left", "right", "bottom", "top") – where to place the colorbar

• cbar_size (string (percentage)) – scaling of the colorbar (e.g., “5%”)

• cbar_mode (one of "each", "single", "edge", None) – how to represent the colorbar

• cbar_pad (string (percentage)) – padding between the axis and colorbar (e.g. “5%”)

Returns

Return type

The return is a matplotlib figure object.

Examples

>>> import yt
>>> ds = yt.load_sample("IsolatedGalaxy")
>>> fields = ["density", "velocity_x", "velocity_y", "velocity_magnitude"]
>>> p = yt.SlicePlot(ds, "z", fields)
>>> p.set_log("velocity_x", False)
>>> p.set_log("velocity_y", False)
>>> fig = p.export_to_mpl_figure((2, 2))
>>> fig.tight_layout()
>>> fig.savefig("test.png")

property frb

The frb property.

get_log(field)

get the transform type of a field.

Parameters

field (string) – the field to get a transform if field == ‘all’, applies to all plots.

hide_axes(field=None, draw_frame=False)

Hides the axes for a plot and updates the size of the plot accordingly. Defaults to operating on all fields for a PlotContainer object.

Parameters
• field (string, field tuple, or list of strings or field tuples (optional)) – The name of the field(s) that we want to hide the axes.

• draw_frame (boolean) – If True, the axes frame will still be drawn. Defaults to False. See note below for more details.

Examples

This will save an image with no axes.

>>> import yt
>>> ds = yt.load("IsolatedGalaxy/galaxy0030/galaxy0030")
>>> s = SlicePlot(ds, 2, "density", "c", (20, "kpc"))
>>> s.hide_axes()
>>> s.save()


This will save an image with no axis or colorbar.

>>> import yt
>>> ds = yt.load("IsolatedGalaxy/galaxy0030/galaxy0030")
>>> s = SlicePlot(ds, 2, "density", "c", (20, "kpc"))
>>> s.hide_axes()
>>> s.hide_colorbar()
>>> s.save()


Note

By default, when removing the axes, the patch on which the axes are drawn is disabled, making it impossible to later change e.g. the background colour. To force the axes patch to be displayed while still hiding the axes, set the draw_frame keyword argument to True.

hide_colorbar(field=None)

Hides the colorbar for a plot and updates the size of the plot accordingly. Defaults to operating on all fields for a PlotContainer object.

Parameters

field (string, field tuple, or list of strings or field tuples (optional)) – The name of the field(s) that we want to hide the colorbar. If None or ‘all’ is provided, will default to using all fields available for this object.

Examples

This will save an image with no colorbar.

>>> import yt
>>> ds = yt.load("IsolatedGalaxy/galaxy0030/galaxy0030")
>>> s = SlicePlot(ds, 2, "density", "c", (20, "kpc"))
>>> s.hide_colorbar()
>>> s.save()


This will save an image with no axis or colorbar.

>>> import yt
>>> ds = yt.load("IsolatedGalaxy/galaxy0030/galaxy0030")
>>> s = SlicePlot(ds, 2, "density", "c", (20, "kpc"))
>>> s.hide_axes()
>>> s.hide_colorbar()
>>> s.save()

list_annotations()[source]

List the current callbacks for the plot, along with their index. This index can be used with clear_annotations to remove a callback from the current plot.

pan(deltas)

Pan the image by specifying absolute code unit coordinate deltas.

Parameters

deltas (Two-element sequence of floats, quantities, or (float, unit)) –

tuples.

(delta_x, delta_y). If a unit is not supplied the unit is assumed to be code_length.

pan_rel(deltas)

Pan the image by specifying relative deltas, to the FOV.

Parameters

deltas (sequence of floats) – (delta_x, delta_y) in relative code unit coordinates

piter(*args, **kwargs)
refresh()
run_callbacks()[source]
save(name=None, suffix='.png', mpl_kwargs=None)

saves the plot to disk.

Parameters
• name (string or tuple) – The base of the filename. If name is a directory or if name is not set, the filename of the dataset is used. For a tuple, the resulting path will be given by joining the elements of the tuple

• suffix (string) – Specify the image type by its suffix. If not specified, the output type will be inferred from the filename. Defaults to PNG.

• mpl_kwargs (dict) – A dict of keyword arguments to be passed to matplotlib.

• slc.save(mpl_kwargs={"bbox_inches" (>>>) –

set_antialias(aa)

Turn antialiasing on or off.

Parameters

aa (boolean) –

set_axes_unit(unit_name)

Set the unit for display on the x and y axes of the image.

Parameters

unit_name (string or two element tuple of strings) – A unit, available for conversion in the dataset, that the image extents will be displayed in. If set to None, any previous units will be reset. If the unit is None, the default is chosen. If unit_name is ‘1’, ‘u’, or ‘unitary’, it will not display the units, and only show the axes name. If unit_name is a tuple, the first element is assumed to be the unit for the x axis and the second element the unit for the y axis.

Raises

YTUnitNotRecognized – If the unit is not known, this will be raised.

Examples

>>> from yt import load
>>> ds = load("IsolatedGalaxy/galaxy0030/galaxy0030")
>>> p = ProjectionPlot(ds, "y", "Density")
>>> p.set_axes_unit("kpc")

set_background_color(field, color=None)

set the background color to match provided color

Parameters
• field (string) – the field to set the colormap if field == ‘all’, applies to all plots.

• color (string or RGBA tuple (optional)) – if set, set the background color to this color if unset, background color is set to the bottom value of the color map

set_buff_size(size)

Sets a new buffer size for the fixed resolution buffer

Parameters

size (int or two element sequence of ints) – The number of data elements in the buffer on the x and y axes. If a scalar is provided, then the buffer is assumed to be square.

set_cbar_minorticks(field, state)

turn colorbar minor ticks “on” or “off” in the current plot, following state

Parameters
• field (string) – the field to remove colorbar minorticks

• state (string) – the state indicating ‘on’ or ‘off’

set_center(new_center, unit='code_length')

Sets a new center for the plot window

Parameters
• new_center (two element sequence of floats) – The coordinates of the new center of the image in the coordinate system defined by the plot axes. If the unit keyword is not specified, the coordinates are assumed to be in code units.

• unit (string) – The name of the unit new_center is given in. If new_center is a YTArray or tuple of YTQuantities, this keyword is ignored.

set_cmap(field, cmap)

set the colormap for one of the fields

Parameters
• field (string) – the field to set the colormap if field == ‘all’, applies to all plots.

• cmap (string or tuple) – If a string, will be interpreted as name of the colormap. If a tuple, it is assumed to be of the form (name, type, number) to be used for palettable functionality. (name, type, number, bool) can be used to specify if a reverse colormap is to be used.

set_colorbar_label(field, label)

Sets the colorbar label.

Parameters
• field (str or tuple) – The name of the field to modify the label for.

• label (str) – The new label

• plot.set_colorbar_label( (>>>) –

• ("gas", "density"), "Dark Matter Density (g cm$^{-3}$)" (..) –

• ) (..) –

set_colorbar_minorticks(field, state)

turn colorbar minor ticks on or off in the current plot

Displaying minor ticks reduces performance; turn them off using set_colorbar_minorticks(‘all’, False) if drawing speed is a problem.

Parameters
• field (string) – the field to remove colorbar minorticks if field == ‘all’, applies to all plots.

• state (bool) – the state indicating ‘on’ (True) or ‘off’ (False)

set_figure_size(size)

Sets a new figure size for the plot

Parameters

size (float) – The size of the figure on the longest axis (in units of inches), including the margins but not the colorbar.

set_font(font_dict=None)

Set the font and font properties.

Parameters

font_dict (dict) –

A dict of keyword parameters to be passed to matplotlib.font_manager.FontProperties.

Possible keys include:

• family - The font family. Can be serif, sans-serif, cursive, ‘fantasy’ or ‘monospace’.

• style - The font style. Either normal, italic or oblique.

• color - A valid color string like ‘r’, ‘g’, ‘red’, ‘cobalt’, and ‘orange’.

• variant - Either normal or small-caps.

• size - Either a relative value of xx-small, x-small, small, medium, large, x-large, xx-large or an absolute font size, e.g. 12

• stretch - A numeric value in the range 0-1000 or one of ultra-condensed, extra-condensed, condensed, semi-condensed, normal, semi-expanded, expanded, extra-expanded or ultra-expanded

• weight - A numeric value in the range 0-1000 or one of ultralight, light, normal, regular, book, medium, roman, semibold, demibold, demi, bold, heavy, extra bold, or black

See the matplotlib font manager API documentation for more details. https://matplotlib.org/stable/api/font_manager_api.html

Notes

Mathtext axis labels will only obey the size and color keyword.

Examples

This sets the font to be 24-pt, blue, sans-serif, italic, and bold-face.

>>> slc = SlicePlot(ds, "x", "Density")
>>> slc.set_font(
...     {
...         "family": "sans-serif",
...         "style": "italic",
...         "weight": "bold",
...         "size": 24,
...         "color": "blue",
...     }
... )

set_font_size(size)

Set the size of the font used in the plot

This sets the font size by calling the set_font function. See set_font for more font customization options.

Parameters
• size (float) –

• absolute size of the font in points (1 pt = 1/72 inch) (The) –

set_log(field, log, linthresh=None, symlog_auto=False)

set a field to log, linear, or symlog.

Symlog scaling is a combination of linear and log, where from 0 to a threshold value, it operates as linear, and then beyond that it operates as log. Symlog can also work with negative values in log space as well as negative and positive values simultaneously and symmetrically. If symlog scaling is desired, please set log=True and either set symlog_auto=True or select a alue for linthresh.

Parameters
• field (string) – the field to set a transform if field == ‘all’, applies to all plots.

• log (boolean) – Log on/off: on means log scaling; off means linear scaling. Unless a linthresh is set or symlog_auto is set in which case symlog is used.

• linthresh (float, optional) – when using symlog scaling, linthresh is the value at which scaling transitions from linear to logarithmic. linthresh must be positive. Note: setting linthresh will automatically enable symlog scale

• symlog_auto (boolean) – if symlog_auto is True, then yt will use symlog scaling and attempt to determine a linthresh automatically. Setting a linthresh manually overrides this value.

set_minorticks(field, state)

Turn minor ticks on or off in the current plot.

Displaying minor ticks reduces performance; turn them off using set_minorticks(‘all’, False) if drawing speed is a problem.

Parameters
• field (string) – the field to remove minorticks if field == ‘all’, applies to all plots.

• state (bool) – the state indicating ‘on’ (True) or ‘off’ (False)

set_mpl_projection(mpl_proj)

Set the matplotlib projection type with a cartopy transform function

Given a string or a tuple argument, this will project the data onto the plot axes with the chosen transform function.

Assumes that the underlying data has a PlateCarree transform type.

To annotate the plot with coastlines or other annotations, _setup_plots() will need to be called after this function to make the axes available for annotation.

Parameters

mpl_proj (string or tuple) – if passed as a string, mpl_proj is the specified projection type, if passed as a tuple, then tuple will take the form of ("ProjectionType", (args)) or ("ProjectionType", (args), {kwargs}) Valid projection type options include: ‘PlateCarree’, ‘LambertConformal’, ‘LabmbertCylindrical’, ‘Mercator’, ‘Miller’, ‘Mollweide’, ‘Orthographic’, ‘Robinson’, ‘Stereographic’, ‘TransverseMercator’, ‘InterruptedGoodeHomolosine’, ‘RotatedPole’, ‘OGSB’, ‘EuroPP’, ‘Geostationary’, ‘Gnomonic’, ‘NorthPolarStereo’, ‘OSNI’, ‘SouthPolarStereo’, ‘AlbersEqualArea’, ‘AzimuthalEquidistant’, ‘Sinusoidal’, ‘UTM’, ‘NearsidePerspective’, ‘LambertAzimuthalEqualArea’

Examples

This will create a Mollweide projection using Mollweide default values and annotate it with coastlines

>>> import yt
>>> ds = yt.load("")
>>> p = yt.SlicePlot(ds, "altitude", "AIRDENS")
>>> p.set_mpl_projection("AIRDENS", "Mollweide")
>>> p._setup_plots()
>>> p.plots["AIRDENS"].axes.coastlines()
>>> p.show()


This will move the PlateCarree central longitude to 90 degrees and annotate with coastlines.

>>> import yt
>>> ds = yt.load("")
>>> p = yt.SlicePlot(ds, "altitude", "AIRDENS")
>>> p.set_mpl_projection(
...     "AIRDENS", ("PlateCarree", (), {"central_longitude": 90, "globe": None})
... )
>>> p._setup_plots()
>>> p.plots["AIRDENS"].axes.set_global()
>>> p.plots["AIRDENS"].axes.coastlines()
>>> p.show()


This will create a RoatatedPole projection with the unrotated pole position at 37.5 degrees latitude and 177.5 degrees longitude by passing them in as args.

>>> import yt
>>> ds = yt.load("")
>>> p = yt.SlicePlot(ds, "altitude", "AIRDENS")
>>> p.set_mpl_projection("RotatedPole", (177.5, 37.5))
>>> p._setup_plots()
>>> p.plots["AIRDENS"].axes.set_global()
>>> p.plots["AIRDENS"].axes.coastlines()
>>> p.show()


This will create a RoatatedPole projection with the unrotated pole position at 37.5 degrees latitude and 177.5 degrees longitude by passing them in as kwargs.

>>> import yt
>>> ds = yt.load("")
>>> p = yt.SlicePlot(ds, "altitude", "AIRDENS")
>>> p.set_mpl_projection(
...     ("RotatedPole", (), {"pole_latitude": 37.5, "pole_longitude": 177.5})
... )
>>> p._setup_plots()
>>> p.plots["AIRDENS"].axes.set_global()
>>> p.plots["AIRDENS"].axes.coastlines()
>>> p.show()

set_origin(origin)

Set the plot origin.

Parameters
• origin (string or length 1, 2, or 3 sequence.) – The location of the origin of the plot coordinate system. This is typically represented by a ‘-‘ separated string or a tuple of strings. In the first index the y-location is given by ‘lower’, ‘upper’, or ‘center’. The second index is the x-location, given as ‘left’, ‘right’, or ‘center’. Finally, whether the origin is applied in ‘domain’ space, plot ‘window’ space or ‘native’ simulation coordinate system is given. For example, both ‘upper-right-domain’ and [‘upper’, ‘right’, ‘domain’] place the origin in the upper right hand corner of domain space. If x or y are not given, a value is inferred. For instance, ‘left-domain’ corresponds to the lower-left hand corner of the simulation domain, ‘center-domain’ corresponds to the center of the simulation domain, or ‘center-window’ for the center of the plot window. In the event that none of these options place the origin in a desired location, a sequence of tuples and a string specifying the coordinate space can be given. If plain numeric types are input, units of code_length are assumed. Further examples:

• =============================== (===============================================) –

• example (format) –

• ===============================

• 'domain' ('{space}') –

• 'left-window' ('{xloc}-{space}') –

• 'upper-domain' ('{yloc}-{space}') –

• 'lower-right-window' ('{yloc}-{xloc}-{space}') –

• ('window',) (('{space}',)) –

• '{space}') ('right', 'domain') (('{xloc}',) –

• '{space}') ('lower', 'window') (('{yloc}',) –

• '{xloc}', '{space}') ('lower', 'right', 'window') (('{yloc}',) –

• '{unit}'), (xloc, '{unit}'), '{space}') ((0, 'm'), (4, 'm'), 'window') (((yloc,) –

• yloc, '{space}') (0.23, 0.5, 'domain') ((xloc,) –

• ===============================

set_transform(field, name)
set_unit(field, new_unit, equivalency=None, equivalency_kwargs=None)

Sets a new unit for the requested field

Parameters
• field (string or field tuple) – The name of the field that is to be changed.

• new_unit (string or Unit object) – The name of the new unit.

• equivalency (string, optional) – If set, the equivalency to use to convert the current units to the new requested unit. If None, the unit conversion will be done without an equivalency

• equivalency_kwargs (string, optional) – Keyword arguments to be passed to the equivalency. Only used if equivalency is set.

set_width(width, unit=None)

set the width of the plot window

Parameters
• width (float, array of floats, (float, unit) tuple, or tuple of) –

(float, unit) tuples.

Width can have four different formats to support windows with variable x and y widths. They are:

format

example

(float, string)

(10,’kpc’)

((float, string), (float, string))

((10,’kpc’),(15,’kpc’))

float

0.2

(float, float)

(0.2, 0.3)

For example, (10, ‘kpc’) requests a plot window that is 10 kiloparsecs wide in the x and y directions, ((10,’kpc’),(15,’kpc’)) requests a window that is 10 kiloparsecs wide along the x axis and 15 kiloparsecs wide along the y axis. In the other two examples, code units are assumed, for example (0.2, 0.3) requests a plot that has an x width of 0.2 and a y width of 0.3 in code units. If units are provided the resulting plot axis labels will use the supplied units.

• unit (str) – the unit the width has been specified in. If width is a tuple, this argument is ignored. Defaults to code units.

set_window_size(size)

This calls set_figure_size to adjust the size of the plot window.

set_xlabel(label)

Allow the user to modify the X-axis title Defaults to the global value. Fontsize defaults to 18.

Parameters
• label (str) – The new string for the x-axis.

• plot.set_xlabel("H2I Number Density (cm$^{-3}$)") (>>>) –

set_ylabel(label)

Allow the user to modify the Y-axis title Defaults to the global value.

Parameters
• label (str) – The new string for the y-axis.

• plot.set_ylabel("Temperature (K)") (>>>) –

set_zlim(field, zmin, zmax, dynamic_range=None)

set the scale of the colormap

Parameters
• field (string) – the field to set a colormap scale if field == ‘all’, applies to all plots.

• zmin (float, tuple, YTQuantity or str) – the new minimum of the colormap scale. If ‘min’, will set to the minimum value in the current view.

• zmax (float, tuple, YTQuantity or str) – the new maximum of the colormap scale. If ‘max’, will set to the maximum value in the current view.

Other Parameters

dynamic_range (float (default: None)) – The dynamic range of the image. If zmin == None, will set zmin = zmax / dynamic_range If zmax == None, will set zmax = zmin * dynamic_range When dynamic_range is specified, defaults to setting zmin = zmax / dynamic_range.

setup_callbacks()[source]
setup_defaults()
show()

This will send any existing plots to the IPython notebook.

If yt is being run from within an IPython session, and it is able to determine this, this function will send any existing plots to the notebook for display.

If yt can’t determine if it’s inside an IPython session, it will raise YTNotInsideNotebook.

Examples

>>> from yt.mods import SlicePlot
>>> slc = SlicePlot(
...     ds, "x", [("gas", "density"), ("gas", "velocity_magnitude")]
... )
>>> slc.show()

show_axes(field=None)

Shows the axes for a plot and updates the size of the plot accordingly. Defaults to operating on all fields for a PlotContainer object. See hide_axes().

Parameters

field (string, field tuple, or list of strings or field tuples (optional)) – The name of the field(s) that we want to show the axes.

show_colorbar(field=None)

Shows the colorbar for a plot and updates the size of the plot accordingly. Defaults to operating on all fields for a PlotContainer object. See hide_colorbar().

Parameters
• field (string, field tuple, or list of strings or field tuples (optional)) –

• name of the field(s) that we want to show the colorbar. (The) –

to_fits_data(fields=None, other_keys=None, length_unit=None, **kwargs)

Export the fields in this PlotWindow instance to a FITSImageData instance.

This will export a set of FITS images of either the fields specified or all the fields already in the object.

Parameters
• fields (list of strings) – These fields will be pixelized and output. If “None”, the keys of the FRB will be used.

• other_keys (dictionary, optional) – A set of header keys and values to write into the FITS header.

• length_unit (string, optional) – the length units that the coordinates are written in. The default is to use the default length unit of the dataset.

toggle_right_handed()
property width
zoom(factor)

This zooms the window by factor > 0. - zoom out with factor < 1 - zoom in with factor > 1

Parameters

factor (float) – multiplier for the current width

class yt.visualization.plot_window.PlotWindow(data_source, bounds, buff_size=800, 800, antialias=True, periodic=True, origin='center-window', oblique=False, right_handed=True, window_size=8.0, fields=None, fontsize=18, aspect=None, setup=False)[source]

A plotting mechanism based around the concept of a window into a data source. It can have arbitrary fields, each of which will be centered on the same viewpoint, but will have individual zlimits.

The data and plot are updated separately, and each can be invalidated as the object is modified.

Data is handled by a FixedResolutionBuffer object.

Parameters
• data_sourceyt.data_objects.selection_objects.base_objects.YTSelectionContainer2D This is the source to be pixelized, which can be a projection, slice, or a cutting plane.

• bounds (sequence of floats) – Bounds are the min and max in the image plane that we want our image to cover. It’s in the order of (xmin, xmax, ymin, ymax), where the coordinates are all in the appropriate code units.

• buff_size (sequence of ints) – The size of the image to generate.

• antialias (boolean) – This can be true or false. It determines whether or not sub-pixel rendering is used during data deposition.

• window_size (float) – The size of the window on the longest axis (in units of inches), including the margins but not the colorbar.

• right_handed (boolean) – Whether the implicit east vector for the image generated is set to make a right handed coordinate system with a north vector and the normal vector, the direction of the ‘window’ into the data.

property bounds
display(name=None, mpl_kwargs=None)

Will attempt to show the plot in in an IPython notebook. Failing that, the plot will be saved to disk.

property frb

The frb property.

get_log(field)

get the transform type of a field.

Parameters

field (string) – the field to get a transform if field == ‘all’, applies to all plots.

hide_axes(field=None, draw_frame=False)

Hides the axes for a plot and updates the size of the plot accordingly. Defaults to operating on all fields for a PlotContainer object.

Parameters
• field (string, field tuple, or list of strings or field tuples (optional)) – The name of the field(s) that we want to hide the axes.

• draw_frame (boolean) – If True, the axes frame will still be drawn. Defaults to False. See note below for more details.

Examples

This will save an image with no axes.

>>> import yt
>>> ds = yt.load("IsolatedGalaxy/galaxy0030/galaxy0030")
>>> s = SlicePlot(ds, 2, "density", "c", (20, "kpc"))
>>> s.hide_axes()
>>> s.save()


This will save an image with no axis or colorbar.

>>> import yt
>>> ds = yt.load("IsolatedGalaxy/galaxy0030/galaxy0030")
>>> s = SlicePlot(ds, 2, "density", "c", (20, "kpc"))
>>> s.hide_axes()
>>> s.hide_colorbar()
>>> s.save()


Note

By default, when removing the axes, the patch on which the axes are drawn is disabled, making it impossible to later change e.g. the background colour. To force the axes patch to be displayed while still hiding the axes, set the draw_frame keyword argument to True.

hide_colorbar(field=None)

Hides the colorbar for a plot and updates the size of the plot accordingly. Defaults to operating on all fields for a PlotContainer object.

Parameters

field (string, field tuple, or list of strings or field tuples (optional)) – The name of the field(s) that we want to hide the colorbar. If None or ‘all’ is provided, will default to using all fields available for this object.

Examples

This will save an image with no colorbar.

>>> import yt
>>> ds = yt.load("IsolatedGalaxy/galaxy0030/galaxy0030")
>>> s = SlicePlot(ds, 2, "density", "c", (20, "kpc"))
>>> s.hide_colorbar()
>>> s.save()


This will save an image with no axis or colorbar.

>>> import yt
>>> ds = yt.load("IsolatedGalaxy/galaxy0030/galaxy0030")
>>> s = SlicePlot(ds, 2, "density", "c", (20, "kpc"))
>>> s.hide_axes()
>>> s.hide_colorbar()
>>> s.save()

pan(deltas)[source]

Pan the image by specifying absolute code unit coordinate deltas.

Parameters

deltas (Two-element sequence of floats, quantities, or (float, unit)) –

tuples.

(delta_x, delta_y). If a unit is not supplied the unit is assumed to be code_length.

pan_rel(deltas)[source]

Pan the image by specifying relative deltas, to the FOV.

Parameters

deltas (sequence of floats) – (delta_x, delta_y) in relative code unit coordinates

piter(*args, **kwargs)[source]
refresh()
save(name=None, suffix='.png', mpl_kwargs=None)

saves the plot to disk.

Parameters
• name (string or tuple) – The base of the filename. If name is a directory or if name is not set, the filename of the dataset is used. For a tuple, the resulting path will be given by joining the elements of the tuple

• suffix (string) – Specify the image type by its suffix. If not specified, the output type will be inferred from the filename. Defaults to PNG.

• mpl_kwargs (dict) – A dict of keyword arguments to be passed to matplotlib.

• slc.save(mpl_kwargs={"bbox_inches" (>>>) –

set_antialias(aa)[source]

Turn antialiasing on or off.

Parameters

aa (boolean) –

set_axes_unit(unit_name)[source]

Set the unit for display on the x and y axes of the image.

Parameters

unit_name (string or two element tuple of strings) – A unit, available for conversion in the dataset, that the image extents will be displayed in. If set to None, any previous units will be reset. If the unit is None, the default is chosen. If unit_name is ‘1’, ‘u’, or ‘unitary’, it will not display the units, and only show the axes name. If unit_name is a tuple, the first element is assumed to be the unit for the x axis and the second element the unit for the y axis.

Raises

YTUnitNotRecognized – If the unit is not known, this will be raised.

Examples

>>> from yt import load
>>> ds = load("IsolatedGalaxy/galaxy0030/galaxy0030")
>>> p = ProjectionPlot(ds, "y", "Density")
>>> p.set_axes_unit("kpc")

set_background_color(field, color=None)

set the background color to match provided color

Parameters
• field (string) – the field to set the colormap if field == ‘all’, applies to all plots.

• color (string or RGBA tuple (optional)) – if set, set the background color to this color if unset, background color is set to the bottom value of the color map

set_buff_size(size)[source]

Sets a new buffer size for the fixed resolution buffer

Parameters

size (int or two element sequence of ints) – The number of data elements in the buffer on the x and y axes. If a scalar is provided, then the buffer is assumed to be square.

set_cbar_minorticks(field, state)

turn colorbar minor ticks “on” or “off” in the current plot, following state

Parameters
• field (string) – the field to remove colorbar minorticks

• state (string) – the state indicating ‘on’ or ‘off’

set_center(new_center, unit='code_length')[source]

Sets a new center for the plot window

Parameters
• new_center (two element sequence of floats) – The coordinates of the new center of the image in the coordinate system defined by the plot axes. If the unit keyword is not specified, the coordinates are assumed to be in code units.

• unit (string) – The name of the unit new_center is given in. If new_center is a YTArray or tuple of YTQuantities, this keyword is ignored.

set_cmap(field, cmap)

set the colormap for one of the fields

Parameters
• field (string) – the field to set the colormap if field == ‘all’, applies to all plots.

• cmap (string or tuple) – If a string, will be interpreted as name of the colormap. If a tuple, it is assumed to be of the form (name, type, number) to be used for palettable functionality. (name, type, number, bool) can be used to specify if a reverse colormap is to be used.

set_colorbar_label(field, label)

Sets the colorbar label.

Parameters
• field (str or tuple) – The name of the field to modify the label for.

• label (str) – The new label

• plot.set_colorbar_label( (>>>) –

• ("gas", "density"), "Dark Matter Density (g cm$^{-3}$)" (..) –

• ) (..) –

set_colorbar_minorticks(field, state)

turn colorbar minor ticks on or off in the current plot

Displaying minor ticks reduces performance; turn them off using set_colorbar_minorticks(‘all’, False) if drawing speed is a problem.

Parameters
• field (string) – the field to remove colorbar minorticks if field == ‘all’, applies to all plots.

• state (bool) – the state indicating ‘on’ (True) or ‘off’ (False)

set_figure_size(size)

Sets a new figure size for the plot

Parameters

size (float) – The size of the figure on the longest axis (in units of inches), including the margins but not the colorbar.

set_font(font_dict=None)

Set the font and font properties.

Parameters

font_dict (dict) –

A dict of keyword parameters to be passed to matplotlib.font_manager.FontProperties.

Possible keys include:

• family - The font family. Can be serif, sans-serif, cursive, ‘fantasy’ or ‘monospace’.

• style - The font style. Either normal, italic or oblique.

• color - A valid color string like ‘r’, ‘g’, ‘red’, ‘cobalt’, and ‘orange’.

• variant - Either normal or small-caps.

• size - Either a relative value of xx-small, x-small, small, medium, large, x-large, xx-large or an absolute font size, e.g. 12

• stretch - A numeric value in the range 0-1000 or one of ultra-condensed, extra-condensed, condensed, semi-condensed, normal, semi-expanded, expanded, extra-expanded or ultra-expanded

• weight - A numeric value in the range 0-1000 or one of ultralight, light, normal, regular, book, medium, roman, semibold, demibold, demi, bold, heavy, extra bold, or black

See the matplotlib font manager API documentation for more details. https://matplotlib.org/stable/api/font_manager_api.html

Notes

Mathtext axis labels will only obey the size and color keyword.

Examples

This sets the font to be 24-pt, blue, sans-serif, italic, and bold-face.

>>> slc = SlicePlot(ds, "x", "Density")
>>> slc.set_font(
...     {
...         "family": "sans-serif",
...         "style": "italic",
...         "weight": "bold",
...         "size": 24,
...         "color": "blue",
...     }
... )

set_font_size(size)

Set the size of the font used in the plot

This sets the font size by calling the set_font function. See set_font for more font customization options.

Parameters
• size (float) –

• absolute size of the font in points (1 pt = 1/72 inch) (The) –

set_log(field, log, linthresh=None, symlog_auto=False)

set a field to log, linear, or symlog.

Symlog scaling is a combination of linear and log, where from 0 to a threshold value, it operates as linear, and then beyond that it operates as log. Symlog can also work with negative values in log space as well as negative and positive values simultaneously and symmetrically. If symlog scaling is desired, please set log=True and either set symlog_auto=True or select a alue for linthresh.

Parameters
• field (string) – the field to set a transform if field == ‘all’, applies to all plots.

• log (boolean) – Log on/off: on means log scaling; off means linear scaling. Unless a linthresh is set or symlog_auto is set in which case symlog is used.

• linthresh (float, optional) – when using symlog scaling, linthresh is the value at which scaling transitions from linear to logarithmic. linthresh must be positive. Note: setting linthresh will automatically enable symlog scale

• symlog_auto (boolean) – if symlog_auto is True, then yt will use symlog scaling and attempt to determine a linthresh automatically. Setting a linthresh manually overrides this value.

set_minorticks(field, state)

Turn minor ticks on or off in the current plot.

Displaying minor ticks reduces performance; turn them off using set_minorticks(‘all’, False) if drawing speed is a problem.

Parameters
• field (string) – the field to remove minorticks if field == ‘all’, applies to all plots.

• state (bool) – the state indicating ‘on’ (True) or ‘off’ (False)

set_mpl_projection(mpl_proj)[source]

Set the matplotlib projection type with a cartopy transform function

Given a string or a tuple argument, this will project the data onto the plot axes with the chosen transform function.

Assumes that the underlying data has a PlateCarree transform type.

To annotate the plot with coastlines or other annotations, _setup_plots() will need to be called after this function to make the axes available for annotation.

Parameters

mpl_proj (string or tuple) – if passed as a string, mpl_proj is the specified projection type, if passed as a tuple, then tuple will take the form of ("ProjectionType", (args)) or ("ProjectionType", (args), {kwargs}) Valid projection type options include: ‘PlateCarree’, ‘LambertConformal’, ‘LabmbertCylindrical’, ‘Mercator’, ‘Miller’, ‘Mollweide’, ‘Orthographic’, ‘Robinson’, ‘Stereographic’, ‘TransverseMercator’, ‘InterruptedGoodeHomolosine’, ‘RotatedPole’, ‘OGSB’, ‘EuroPP’, ‘Geostationary’, ‘Gnomonic’, ‘NorthPolarStereo’, ‘OSNI’, ‘SouthPolarStereo’, ‘AlbersEqualArea’, ‘AzimuthalEquidistant’, ‘Sinusoidal’, ‘UTM’, ‘NearsidePerspective’, ‘LambertAzimuthalEqualArea’

Examples

This will create a Mollweide projection using Mollweide default values and annotate it with coastlines

>>> import yt
>>> ds = yt.load("")
>>> p = yt.SlicePlot(ds, "altitude", "AIRDENS")
>>> p.set_mpl_projection("AIRDENS", "Mollweide")
>>> p._setup_plots()
>>> p.plots["AIRDENS"].axes.coastlines()
>>> p.show()


This will move the PlateCarree central longitude to 90 degrees and annotate with coastlines.

>>> import yt
>>> ds = yt.load("")
>>> p = yt.SlicePlot(ds, "altitude", "AIRDENS")
>>> p.set_mpl_projection(
...     "AIRDENS", ("PlateCarree", (), {"central_longitude": 90, "globe": None})
... )
>>> p._setup_plots()
>>> p.plots["AIRDENS"].axes.set_global()
>>> p.plots["AIRDENS"].axes.coastlines()
>>> p.show()


This will create a RoatatedPole projection with the unrotated pole position at 37.5 degrees latitude and 177.5 degrees longitude by passing them in as args.

>>> import yt
>>> ds = yt.load("")
>>> p = yt.SlicePlot(ds, "altitude", "AIRDENS")
>>> p.set_mpl_projection("RotatedPole", (177.5, 37.5))
>>> p._setup_plots()
>>> p.plots["AIRDENS"].axes.set_global()
>>> p.plots["AIRDENS"].axes.coastlines()
>>> p.show()


This will create a RoatatedPole projection with the unrotated pole position at 37.5 degrees latitude and 177.5 degrees longitude by passing them in as kwargs.

>>> import yt
>>> ds = yt.load("")
>>> p = yt.SlicePlot(ds, "altitude", "AIRDENS")
>>> p.set_mpl_projection(
...     ("RotatedPole", (), {"pole_latitude": 37.5, "pole_longitude": 177.5})
... )
>>> p._setup_plots()
>>> p.plots["AIRDENS"].axes.set_global()
>>> p.plots["AIRDENS"].axes.coastlines()
>>> p.show()

set_origin(origin)[source]

Set the plot origin.

Parameters
• origin (string or length 1, 2, or 3 sequence.) – The location of the origin of the plot coordinate system. This is typically represented by a ‘-‘ separated string or a tuple of strings. In the first index the y-location is given by ‘lower’, ‘upper’, or ‘center’. The second index is the x-location, given as ‘left’, ‘right’, or ‘center’. Finally, whether the origin is applied in ‘domain’ space, plot ‘window’ space or ‘native’ simulation coordinate system is given. For example, both ‘upper-right-domain’ and [‘upper’, ‘right’, ‘domain’] place the origin in the upper right hand corner of domain space. If x or y are not given, a value is inferred. For instance, ‘left-domain’ corresponds to the lower-left hand corner of the simulation domain, ‘center-domain’ corresponds to the center of the simulation domain, or ‘center-window’ for the center of the plot window. In the event that none of these options place the origin in a desired location, a sequence of tuples and a string specifying the coordinate space can be given. If plain numeric types are input, units of code_length are assumed. Further examples:

• =============================== (===============================================) –

• example (format) –

• ===============================

• 'domain' ('{space}') –

• 'left-window' ('{xloc}-{space}') –

• 'upper-domain' ('{yloc}-{space}') –

• 'lower-right-window' ('{yloc}-{xloc}-{space}') –

• ('window',) (('{space}',)) –

• '{space}') ('right', 'domain') (('{xloc}',) –

• '{space}') ('lower', 'window') (('{yloc}',) –

• '{xloc}', '{space}') ('lower', 'right', 'window') (('{yloc}',) –

• '{unit}'), (xloc, '{unit}'), '{space}') ((0, 'm'), (4, 'm'), 'window') (((yloc,) –

• yloc, '{space}') (0.23, 0.5, 'domain') ((xloc,) –

• ===============================

set_transform(field, name)
set_unit(field, new_unit, equivalency=None, equivalency_kwargs=None)[source]

Sets a new unit for the requested field

Parameters
• field (string or field tuple) – The name of the field that is to be changed.

• new_unit (string or Unit object) – The name of the new unit.

• equivalency (string, optional) – If set, the equivalency to use to convert the current units to the new requested unit. If None, the unit conversion will be done without an equivalency

• equivalency_kwargs (string, optional) – Keyword arguments to be passed to the equivalency. Only used if equivalency is set.

set_width(width, unit=None)[source]

set the width of the plot window

Parameters
• width (float, array of floats, (float, unit) tuple, or tuple of) –

(float, unit) tuples.

Width can have four different formats to support windows with variable x and y widths. They are:

format

example

(float, string)

(10,’kpc’)

((float, string), (float, string))

((10,’kpc’),(15,’kpc’))

float

0.2

(float, float)

(0.2, 0.3)

For example, (10, ‘kpc’) requests a plot window that is 10 kiloparsecs wide in the x and y directions, ((10,’kpc’),(15,’kpc’)) requests a window that is 10 kiloparsecs wide along the x axis and 15 kiloparsecs wide along the y axis. In the other two examples, code units are assumed, for example (0.2, 0.3) requests a plot that has an x width of 0.2 and a y width of 0.3 in code units. If units are provided the resulting plot axis labels will use the supplied units.

• unit (str) – the unit the width has been specified in. If width is a tuple, this argument is ignored. Defaults to code units.

set_window_size(size)[source]

This calls set_figure_size to adjust the size of the plot window.

set_xlabel(label)

Allow the user to modify the X-axis title Defaults to the global value. Fontsize defaults to 18.

Parameters
• label (str) – The new string for the x-axis.

• plot.set_xlabel("H2I Number Density (cm$^{-3}$)") (>>>) –

set_ylabel(label)

Allow the user to modify the Y-axis title Defaults to the global value.

Parameters
• label (str) – The new string for the y-axis.

• plot.set_ylabel("Temperature (K)") (>>>) –

set_zlim(field, zmin, zmax, dynamic_range=None)

set the scale of the colormap

Parameters
• field (string) – the field to set a colormap scale if field == ‘all’, applies to all plots.

• zmin (float, tuple, YTQuantity or str) – the new minimum of the colormap scale. If ‘min’, will set to the minimum value in the current view.

• zmax (float, tuple, YTQuantity or str) – the new maximum of the colormap scale. If ‘max’, will set to the maximum value in the current view.

Other Parameters

dynamic_range (float (default: None)) – The dynamic range of the image. If zmin == None, will set zmin = zmax / dynamic_range If zmax == None, will set zmax = zmin * dynamic_range When dynamic_range is specified, defaults to setting zmin = zmax / dynamic_range.

setup_defaults()
show()

This will send any existing plots to the IPython notebook.

If yt is being run from within an IPython session, and it is able to determine this, this function will send any existing plots to the notebook for display.

If yt can’t determine if it’s inside an IPython session, it will raise YTNotInsideNotebook.

Examples

>>> from yt.mods import SlicePlot
>>> slc = SlicePlot(
...     ds, "x", [("gas", "density"), ("gas", "velocity_magnitude")]
... )
>>> slc.show()

show_axes(field=None)

Shows the axes for a plot and updates the size of the plot accordingly. Defaults to operating on all fields for a PlotContainer object. See hide_axes().

Parameters

field (string, field tuple, or list of strings or field tuples (optional)) – The name of the field(s) that we want to show the axes.

show_colorbar(field=None)

Shows the colorbar for a plot and updates the size of the plot accordingly. Defaults to operating on all fields for a PlotContainer object. See hide_colorbar().

Parameters
• field (string, field tuple, or list of strings or field tuples (optional)) –

• name of the field(s) that we want to show the colorbar. (The) –

to_fits_data(fields=None, other_keys=None, length_unit=None, **kwargs)[source]

Export the fields in this PlotWindow instance to a FITSImageData instance.

This will export a set of FITS images of either the fields specified or all the fields already in the object.

Parameters
• fields (list of strings) – These fields will be pixelized and output. If “None”, the keys of the FRB will be used.

• other_keys (dictionary, optional) – A set of header keys and values to write into the FITS header.

• length_unit (string, optional) – the length units that the coordinates are written in. The default is to use the default length unit of the dataset.

toggle_right_handed()[source]
property width
zoom(factor)[source]

This zooms the window by factor > 0. - zoom out with factor < 1 - zoom in with factor > 1

Parameters

factor (float) – multiplier for the current width

class yt.visualization.plot_window.ProjectionPlot(ds, axis, fields, center='c', width=None, axes_unit=None, weight_field=None, max_level=None, origin='center-window', right_handed=True, fontsize=18, field_parameters=None, data_source=None, method='integrate', proj_style=None, window_size=8.0, buff_size=800, 800, aspect=None)[source]

Creates a projection plot from a dataset

Given a ds object, an axis to project along, and a field name string, this will return a PWViewerMPL object containing the plot.

The plot can be updated using one of the many helper functions defined in PlotWindow.

Parameters
• ds (Dataset) – This is the dataset object corresponding to the simulation output to be plotted.

• axis (int or one of 'x', 'y', 'z') – An int corresponding to the axis to slice along (0=x, 1=y, 2=z) or the axis name itself

• fields (string) – The name of the field(s) to be plotted.

• center (A sequence of floats, a string, or a tuple.) – The coordinate of the center of the image. If set to ‘c’, ‘center’ or left blank, the plot is centered on the middle of the domain. If set to ‘max’ or ‘m’, the center will be located at the maximum of the (‘gas’, ‘density’) field. Centering on the max or min of a specific field is supported by providing a tuple such as (“min”,”temperature”) or (“max”,”dark_matter_density”). Units can be specified by passing in center as a tuple containing a coordinate and string unit name or by passing in a YTArray. If a list or unitless array is supplied, code units are assumed.

• width (tuple or a float.) –

Width can have four different formats to support windows with variable x and y widths. They are:

format

example

(float, string)

(10,’kpc’)

((float, string), (float, string))

((10,’kpc’),(15,’kpc’))

float

0.2

(float, float)

(0.2, 0.3)

For example, (10, ‘kpc’) requests a plot window that is 10 kiloparsecs wide in the x and y directions, ((10,’kpc’),(15,’kpc’)) requests a window that is 10 kiloparsecs wide along the x axis and 15 kiloparsecs wide along the y axis. In the other two examples, code units are assumed, for example (0.2, 0.3) requests a plot that has an x width of 0.2 and a y width of 0.3 in code units. If units are provided the resulting plot axis labels will use the supplied units.

• axes_unit (string) – The name of the unit for the tick labels on the x and y axes. Defaults to None, which automatically picks an appropriate unit. If axes_unit is ‘1’, ‘u’, or ‘unitary’, it will not display the units, and only show the axes name.

• origin (string or length 1, 2, or 3 sequence.) –

The location of the origin of the plot coordinate system. This is typically represented by a ‘-‘ separated string or a tuple of strings. In the first index the y-location is given by ‘lower’, ‘upper’, or ‘center’. The second index is the x-location, given as ‘left’, ‘right’, or ‘center’. Finally, whether the origin is applied in ‘domain’ space, plot ‘window’ space or ‘native’ simulation coordinate system is given. For example, both ‘upper-right-domain’ and [‘upper’, ‘right’, ‘domain’] place the origin in the upper right hand corner of domain space. If x or y are not given, a value is inferred. For instance, ‘left-domain’ corresponds to the lower-left hand corner of the simulation domain, ‘center-domain’ corresponds to the center of the simulation domain, or ‘center-window’ for the center of the plot window. In the event that none of these options place the origin in a desired location, a sequence of tuples and a string specifying the coordinate space can be given. If plain numeric types are input, units of code_length are assumed. Further examples:

format

example

’{space}’

’domain’

’{xloc}-{space}’

’left-window’

’{yloc}-{space}’

’upper-domain’

’{yloc}-{xloc}-{space}’

’lower-right-window’

(‘{space}’,)

(‘window’,)

(‘{xloc}’, ‘{space}’)

(‘right’, ‘domain’)

(‘{yloc}’, ‘{space}’)

(‘lower’, ‘window’)

(‘{yloc}’, ‘{xloc}’, ‘{space}’)

(‘lower’, ‘right’, ‘window’)

((yloc, ‘{unit}’), (xloc, ‘{unit}’), ‘{space}’)

((0, ‘m’), (.4, ‘m’), ‘window’)

(xloc, yloc, ‘{space}’)

(0.23, 0.5, ‘domain’)

• right_handed (boolean) – Whether the implicit east vector for the image generated is set to make a right handed coordinate system with the direction of the ‘window’ into the data.

• data_source (YTSelectionContainer object) – Object to be used for data selection. Defaults to a region covering the entire simulation.

• weight_field (string) – The name of the weighting field. Set to None for no weight.

• max_level (int) – The maximum level to project to.

• fontsize (integer) – The size of the fonts for the axis, colorbar, and tick labels.

• method (string) –

The method of projection. Valid methods are:

”integrate” with no weight_field specified : integrate the requested field along the line of sight.

”integrate” with a weight_field specified : weight the requested field by the weighting field and integrate along the line of sight.

”mip” : pick out the maximum value of the field in the line of sight.

”sum” : This method is the same as integrate, except that it does not multiply by a path length when performing the integration, and is just a straight summation of the field along the given axis. WARNING: This should only be used for uniform resolution grid datasets, as other datasets may result in unphysical images.

• proj_style (string) – The method of projection–same as method keyword. Deprecated as of version 3.0.2. Please use method instead.

• window_size (float) – The size of the window in inches. Set to 8 by default.

• aspect (float) – The aspect ratio of the plot. Set to None for 1.

• field_parameters (dictionary) – A dictionary of field parameters than can be accessed by derived fields.

• data_source – Object to be used for data selection. Defaults to ds.all_data(), a region covering the full domain

• buff_size (length 2 sequence) – Size of the buffer to use for the image, i.e. the number of resolution elements used. Effectively sets a resolution limit to the image if buff_size is smaller than the finest gridding.

Examples

Create a projection plot with a width of 20 kiloparsecs centered on the center of the simulation box:

>>> from yt import load
>>> ds = load("IsolateGalaxygalaxy0030/galaxy0030")
>>> p = ProjectionPlot(ds, "z", ("gas", "density"), width=(20, "kpc"))

annotate_clear(index=None)

Clear callbacks from the plot. If index is not set, clear all callbacks. If index is set, clear that index (ie 0 is the first one created, 1 is the 2nd one created, -1 is the last one created, etc.)

Note

Deprecated in favor of clear_annotations.

property bounds
clear_annotations(index=None)

Clear callbacks from the plot. If index is not set, clear all callbacks. If index is set, clear that index (ie 0 is the first one created, 1 is the 2nd one created, -1 is the last one created, etc.)

display(name=None, mpl_kwargs=None)

Will attempt to show the plot in in an IPython notebook. Failing that, the plot will be saved to disk.

export_to_mpl_figure(nrows_ncols, axes_pad=1.0, label_mode='L', cbar_location='right', cbar_size='5%', cbar_mode='each', cbar_pad='0%')

Creates a matplotlib figure object with the specified axes arrangement, nrows_ncols, and maps the underlying figures to the matplotlib axes. Note that all of these parameters are fed directly to the matplotlib ImageGrid class to create the new figure layout.

Parameters
• nrows_ncols (tuple) – the number of rows and columns of the axis grid (e.g., nrows_ncols=(2,2,))

• axes_pad (float) – padding between axes in inches

• label_mode (one of "L", "1", "all") – arrangement of axes that are labeled

• cbar_location (one of "left", "right", "bottom", "top") – where to place the colorbar

• cbar_size (string (percentage)) – scaling of the colorbar (e.g., “5%”)

• cbar_mode (one of "each", "single", "edge", None) – how to represent the colorbar

• cbar_pad (string (percentage)) – padding between the axis and colorbar (e.g. “5%”)

Returns

Return type

The return is a matplotlib figure object.

Examples

>>> import yt
>>> ds = yt.load_sample("IsolatedGalaxy")
>>> fields = ["density", "velocity_x", "velocity_y", "velocity_magnitude"]
>>> p = yt.SlicePlot(ds, "z", fields)
>>> p.set_log("velocity_x", False)
>>> p.set_log("velocity_y", False)
>>> fig = p.export_to_mpl_figure((2, 2))
>>> fig.tight_layout()
>>> fig.savefig("test.png")

property frb

The frb property.

get_log(field)

get the transform type of a field.

Parameters

field (string) – the field to get a transform if field == ‘all’, applies to all plots.

hide_axes(field=None, draw_frame=False)

Hides the axes for a plot and updates the size of the plot accordingly. Defaults to operating on all fields for a PlotContainer object.

Parameters
• field (string, field tuple, or list of strings or field tuples (optional)) – The name of the field(s) that we want to hide the axes.

• draw_frame (boolean) – If True, the axes frame will still be drawn. Defaults to False. See note below for more details.

Examples

This will save an image with no axes.

>>> import yt
>>> ds = yt.load("IsolatedGalaxy/galaxy0030/galaxy0030")
>>> s = SlicePlot(ds, 2, "density", "c", (20, "kpc"))
>>> s.hide_axes()
>>> s.save()


This will save an image with no axis or colorbar.

>>> import yt
>>> ds = yt.load("IsolatedGalaxy/galaxy0030/galaxy0030")
>>> s = SlicePlot(ds, 2, "density", "c", (20, "kpc"))
>>> s.hide_axes()
>>> s.hide_colorbar()
>>> s.save()


Note

By default, when removing the axes, the patch on which the axes are drawn is disabled, making it impossible to later change e.g. the background colour. To force the axes patch to be displayed while still hiding the axes, set the draw_frame keyword argument to True.

hide_colorbar(field=None)

Hides the colorbar for a plot and updates the size of the plot accordingly. Defaults to operating on all fields for a PlotContainer object.

Parameters

field (string, field tuple, or list of strings or field tuples (optional)) – The name of the field(s) that we want to hide the colorbar. If None or ‘all’ is provided, will default to using all fields available for this object.

Examples

This will save an image with no colorbar.

>>> import yt
>>> ds = yt.load("IsolatedGalaxy/galaxy0030/galaxy0030")
>>> s = SlicePlot(ds, 2, "density", "c", (20, "kpc"))
>>> s.hide_colorbar()
>>> s.save()


This will save an image with no axis or colorbar.

>>> import yt
>>> ds = yt.load("IsolatedGalaxy/galaxy0030/galaxy0030")
>>> s = SlicePlot(ds, 2, "density", "c", (20, "kpc"))
>>> s.hide_axes()
>>> s.hide_colorbar()
>>> s.save()

list_annotations()

List the current callbacks for the plot, along with their index. This index can be used with clear_annotations to remove a callback from the current plot.

pan(deltas)

Pan the image by specifying absolute code unit coordinate deltas.

Parameters

deltas (Two-element sequence of floats, quantities, or (float, unit)) –

tuples.

(delta_x, delta_y). If a unit is not supplied the unit is assumed to be code_length.

pan_rel(deltas)

Pan the image by specifying relative deltas, to the FOV.

Parameters

deltas (sequence of floats) – (delta_x, delta_y) in relative code unit coordinates

piter(*args, **kwargs)
refresh()
run_callbacks()
save(name=None, suffix='.png', mpl_kwargs=None)

saves the plot to disk.

Parameters
• name (string or tuple) – The base of the filename. If name is a directory or if name is not set, the filename of the dataset is used. For a tuple, the resulting path will be given by joining the elements of the tuple

• suffix (string) – Specify the image type by its suffix. If not specified, the output type will be inferred from the filename. Defaults to PNG.

• mpl_kwargs (dict) – A dict of keyword arguments to be passed to matplotlib.

• slc.save(mpl_kwargs={"bbox_inches" (>>>) –

set_antialias(aa)

Turn antialiasing on or off.

Parameters

aa (boolean) –

set_axes_unit(unit_name)

Set the unit for display on the x and y axes of the image.

Parameters

unit_name (string or two element tuple of strings) – A unit, available for conversion in the dataset, that the image extents will be displayed in. If set to None, any previous units will be reset. If the unit is None, the default is chosen. If unit_name is ‘1’, ‘u’, or ‘unitary’, it will not display the units, and only show the axes name. If unit_name is a tuple, the first element is assumed to be the unit for the x axis and the second element the unit for the y axis.

Raises

YTUnitNotRecognized – If the unit is not known, this will be raised.

Examples

>>> from yt import load
>>> ds = load("IsolatedGalaxy/galaxy0030/galaxy0030")
>>> p = ProjectionPlot(ds, "y", "Density")
>>> p.set_axes_unit("kpc")

set_background_color(field, color=None)

set the background color to match provided color

Parameters
• field (string) – the field to set the colormap if field == ‘all’, applies to all plots.

• color (string or RGBA tuple (optional)) – if set, set the background color to this color if unset, background color is set to the bottom value of the color map

set_buff_size(size)

Sets a new buffer size for the fixed resolution buffer

Parameters

size (int or two element sequence of ints) – The number of data elements in the buffer on the x and y axes. If a scalar is provided, then the buffer is assumed to be square.

set_cbar_minorticks(field, state)

turn colorbar minor ticks “on” or “off” in the current plot, following state

Parameters
• field (string) – the field to remove colorbar minorticks

• state (string) – the state indicating ‘on’ or ‘off’

set_center(new_center, unit='code_length')

Sets a new center for the plot window

Parameters
• new_center (two element sequence of floats) – The coordinates of the new center of the image in the coordinate system defined by the plot axes. If the unit keyword is not specified, the coordinates are assumed to be in code units.

• unit (string) – The name of the unit new_center is given in. If new_center is a YTArray or tuple of YTQuantities, this keyword is ignored.

set_cmap(field, cmap)

set the colormap for one of the fields

Parameters
• field (string) – the field to set the colormap if field == ‘all’, applies to all plots.

• cmap (string or tuple) – If a string, will be interpreted as name of the colormap. If a tuple, it is assumed to be of the form (name, type, number) to be used for palettable functionality. (name, type, number, bool) can be used to specify if a reverse colormap is to be used.

set_colorbar_label(field, label)

Sets the colorbar label.

Parameters
• field (str or tuple) – The name of the field to modify the label for.

• label (str) – The new label

• plot.set_colorbar_label( (>>>) –

• ("gas", "density"), "Dark Matter Density (g cm$^{-3}$)" (..) –

• ) (..) –

set_colorbar_minorticks(field, state)

turn colorbar minor ticks on or off in the current plot

Displaying minor ticks reduces performance; turn them off using set_colorbar_minorticks(‘all’, False) if drawing speed is a problem.

Parameters
• field (string) – the field to remove colorbar minorticks if field == ‘all’, applies to all plots.

• state (bool) – the state indicating ‘on’ (True) or ‘off’ (False)

set_figure_size(size)

Sets a new figure size for the plot

Parameters

size (float) – The size of the figure on the longest axis (in units of inches), including the margins but not the colorbar.

set_font(font_dict=None)

Set the font and font properties.

Parameters

font_dict (dict) –

A dict of keyword parameters to be passed to matplotlib.font_manager.FontProperties.

Possible keys include:

• family - The font family. Can be serif, sans-serif, cursive, ‘fantasy’ or ‘monospace’.

• style - The font style. Either normal, italic or oblique.

• color - A valid color string like ‘r’, ‘g’, ‘red’, ‘cobalt’, and ‘orange’.

• variant - Either normal or small-caps.

• size - Either a relative value of xx-small, x-small, small, medium, large, x-large, xx-large or an absolute font size, e.g. 12

• stretch - A numeric value in the range 0-1000 or one of ultra-condensed, extra-condensed, condensed, semi-condensed, normal, semi-expanded, expanded, extra-expanded or ultra-expanded

• weight - A numeric value in the range 0-1000 or one of ultralight, light, normal, regular, book, medium, roman, semibold, demibold, demi, bold, heavy, extra bold, or black

See the matplotlib font manager API documentation for more details. https://matplotlib.org/stable/api/font_manager_api.html

Notes

Mathtext axis labels will only obey the size and color keyword.

Examples

This sets the font to be 24-pt, blue, sans-serif, italic, and bold-face.

>>> slc = SlicePlot(ds, "x", "Density")
>>> slc.set_font(
...     {
...         "family": "sans-serif",
...         "style": "italic",
...         "weight": "bold",
...         "size": 24,
...         "color": "blue",
...     }
... )

set_font_size(size)

Set the size of the font used in the plot

This sets the font size by calling the set_font function. See set_font for more font customization options.

Parameters
• size (float) –

• absolute size of the font in points (1 pt = 1/72 inch) (The) –

set_log(field, log, linthresh=None, symlog_auto=False)

set a field to log, linear, or symlog.

Symlog scaling is a combination of linear and log, where from 0 to a threshold value, it operates as linear, and then beyond that it operates as log. Symlog can also work with negative values in log space as well as negative and positive values simultaneously and symmetrically. If symlog scaling is desired, please set log=True and either set symlog_auto=True or select a alue for linthresh.

Parameters
• field (string) – the field to set a transform if field == ‘all’, applies to all plots.

• log (boolean) – Log on/off: on means log scaling; off means linear scaling. Unless a linthresh is set or symlog_auto is set in which case symlog is used.

• linthresh (float, optional) – when using symlog scaling, linthresh is the value at which scaling transitions from linear to logarithmic. linthresh must be positive. Note: setting linthresh will automatically enable symlog scale

• symlog_auto (boolean) – if symlog_auto is True, then yt will use symlog scaling and attempt to determine a linthresh automatically. Setting a linthresh manually overrides this value.

set_minorticks(field, state)

Turn minor ticks on or off in the current plot.

Displaying minor ticks reduces performance; turn them off using set_minorticks(‘all’, False) if drawing speed is a problem.

Parameters
• field (string) – the field to remove minorticks if field == ‘all’, applies to all plots.

• state (bool) – the state indicating ‘on’ (True) or ‘off’ (False)

set_mpl_projection(mpl_proj)

Set the matplotlib projection type with a cartopy transform function

Given a string or a tuple argument, this will project the data onto the plot axes with the chosen transform function.

Assumes that the underlying data has a PlateCarree transform type.

To annotate the plot with coastlines or other annotations, _setup_plots() will need to be called after this function to make the axes available for annotation.

Parameters

mpl_proj (string or tuple) – if passed as a string, mpl_proj is the specified projection type, if passed as a tuple, then tuple will take the form of ("ProjectionType", (args)) or ("ProjectionType", (args), {kwargs}) Valid projection type options include: ‘PlateCarree’, ‘LambertConformal’, ‘LabmbertCylindrical’, ‘Mercator’, ‘Miller’, ‘Mollweide’, ‘Orthographic’, ‘Robinson’, ‘Stereographic’, ‘TransverseMercator’, ‘InterruptedGoodeHomolosine’, ‘RotatedPole’, ‘OGSB’, ‘EuroPP’, ‘Geostationary’, ‘Gnomonic’, ‘NorthPolarStereo’, ‘OSNI’, ‘SouthPolarStereo’, ‘AlbersEqualArea’, ‘AzimuthalEquidistant’, ‘Sinusoidal’, ‘UTM’, ‘NearsidePerspective’, ‘LambertAzimuthalEqualArea’

Examples

This will create a Mollweide projection using Mollweide default values and annotate it with coastlines

>>> import yt
>>> ds = yt.load("")
>>> p = yt.SlicePlot(ds, "altitude", "AIRDENS")
>>> p.set_mpl_projection("AIRDENS", "Mollweide")
>>> p._setup_plots()
>>> p.plots["AIRDENS"].axes.coastlines()
>>> p.show()


This will move the PlateCarree central longitude to 90 degrees and annotate with coastlines.

>>> import yt
>>> ds = yt.load("")
>>> p = yt.SlicePlot(ds, "altitude", "AIRDENS")
>>> p.set_mpl_projection(
...     "AIRDENS", ("PlateCarree", (), {"central_longitude": 90, "globe": None})
... )
>>> p._setup_plots()
>>> p.plots["AIRDENS"].axes.set_global()
>>> p.plots["AIRDENS"].axes.coastlines()
>>> p.show()


This will create a RoatatedPole projection with the unrotated pole position at 37.5 degrees latitude and 177.5 degrees longitude by passing them in as args.

>>> import yt
>>> ds = yt.load("")
>>> p = yt.SlicePlot(ds, "altitude", "AIRDENS")
>>> p.set_mpl_projection("RotatedPole", (177.5, 37.5))
>>> p._setup_plots()
>>> p.plots["AIRDENS"].axes.set_global()
>>> p.plots["AIRDENS"].axes.coastlines()
>>> p.show()


This will create a RoatatedPole projection with the unrotated pole position at 37.5 degrees latitude and 177.5 degrees longitude by passing them in as kwargs.

>>> import yt
>>> ds = yt.load("")
>>> p = yt.SlicePlot(ds, "altitude", "AIRDENS")
>>> p.set_mpl_projection(
...     ("RotatedPole", (), {"pole_latitude": 37.5, "pole_longitude": 177.5})
... )
>>> p._setup_plots()
>>> p.plots["AIRDENS"].axes.set_global()
>>> p.plots["AIRDENS"].axes.coastlines()
>>> p.show()

set_origin(origin)

Set the plot origin.

Parameters
• origin (string or length 1, 2, or 3 sequence.) – The location of the origin of the plot coordinate system. This is typically represented by a ‘-‘ separated string or a tuple of strings. In the first index the y-location is given by ‘lower’, ‘upper’, or ‘center’. The second index is the x-location, given as ‘left’, ‘right’, or ‘center’. Finally, whether the origin is applied in ‘domain’ space, plot ‘window’ space or ‘native’ simulation coordinate system is given. For example, both ‘upper-right-domain’ and [‘upper’, ‘right’, ‘domain’] place the origin in the upper right hand corner of domain space. If x or y are not given, a value is inferred. For instance, ‘left-domain’ corresponds to the lower-left hand corner of the simulation domain, ‘center-domain’ corresponds to the center of the simulation domain, or ‘center-window’ for the center of the plot window. In the event that none of these options place the origin in a desired location, a sequence of tuples and a string specifying the coordinate space can be given. If plain numeric types are input, units of code_length are assumed. Further examples:

• =============================== (===============================================) –

• example (format) –

• ===============================

• 'domain' ('{space}') –

• 'left-window' ('{xloc}-{space}') –

• 'upper-domain' ('{yloc}-{space}') –

• 'lower-right-window' ('{yloc}-{xloc}-{space}') –

• ('window',) (('{space}',)) –

• '{space}') ('right', 'domain') (('{xloc}',) –

• '{space}') ('lower', 'window') (('{yloc}',) –

• '{xloc}', '{space}') ('lower', 'right', 'window') (('{yloc}',) –

• '{unit}'), (xloc, '{unit}'), '{space}') ((0, 'm'), (4, 'm'), 'window') (((yloc,) –

• yloc, '{space}') (0.23, 0.5, 'domain') ((xloc,) –

• ===============================

set_transform(field, name)
set_unit(field, new_unit, equivalency=None, equivalency_kwargs=None)

Sets a new unit for the requested field

Parameters
• field (string or field tuple) – The name of the field that is to be changed.

• new_unit (string or Unit object) – The name of the new unit.

• equivalency (string, optional) – If set, the equivalency to use to convert the current units to the new requested unit. If None, the unit conversion will be done without an equivalency

• equivalency_kwargs (string, optional) – Keyword arguments to be passed to the equivalency. Only used if equivalency is set.

set_width(width, unit=None)

set the width of the plot window

Parameters
• width (float, array of floats, (float, unit) tuple, or tuple of) –

(float, unit) tuples.

Width can have four different formats to support windows with variable x and y widths. They are:

format

example

(float, string)

(10,’kpc’)

((float, string), (float, string))

((10,’kpc’),(15,’kpc’))

float

0.2

(float, float)

(0.2, 0.3)

For example, (10, ‘kpc’) requests a plot window that is 10 kiloparsecs wide in the x and y directions, ((10,’kpc’),(15,’kpc’)) requests a window that is 10 kiloparsecs wide along the x axis and 15 kiloparsecs wide along the y axis. In the other two examples, code units are assumed, for example (0.2, 0.3) requests a plot that has an x width of 0.2 and a y width of 0.3 in code units. If units are provided the resulting plot axis labels will use the supplied units.

• unit (str) – the unit the width has been specified in. If width is a tuple, this argument is ignored. Defaults to code units.

set_window_size(size)

This calls set_figure_size to adjust the size of the plot window.

set_xlabel(label)

Allow the user to modify the X-axis title Defaults to the global value. Fontsize defaults to 18.

Parameters
• label (str) – The new string for the x-axis.

• plot.set_xlabel("H2I Number Density (cm$^{-3}$)") (>>>) –

set_ylabel(label)

Allow the user to modify the Y-axis title Defaults to the global value.

Parameters
• label (str) – The new string for the y-axis.

• plot.set_ylabel("Temperature (K)") (>>>) –

set_zlim(field, zmin, zmax, dynamic_range=None)

set the scale of the colormap

Parameters
• field (string) – the field to set a colormap scale if field == ‘all’, applies to all plots.

• zmin (float, tuple, YTQuantity or str) – the new minimum of the colormap scale. If ‘min’, will set to the minimum value in the current view.

• zmax (float, tuple, YTQuantity or str) – the new maximum of the colormap scale. If ‘max’, will set to the maximum value in the current view.

Other Parameters

dynamic_range (float (default: None)) – The dynamic range of the image. If zmin == None, will set zmin = zmax / dynamic_range If zmax == None, will set zmax = zmin * dynamic_range When dynamic_range is specified, defaults to setting zmin = zmax / dynamic_range.

setup_callbacks()
setup_defaults()
show()

This will send any existing plots to the IPython notebook.

If yt is being run from within an IPython session, and it is able to determine this, this function will send any existing plots to the notebook for display.

If yt can’t determine if it’s inside an IPython session, it will raise YTNotInsideNotebook.

Examples

>>> from yt.mods import SlicePlot
>>> slc = SlicePlot(
...     ds, "x", [("gas", "density"), ("gas", "velocity_magnitude")]
... )
>>> slc.show()

show_axes(field=None)

Shows the axes for a plot and updates the size of the plot accordingly. Defaults to operating on all fields for a PlotContainer object. See hide_axes().

Parameters

field (string, field tuple, or list of strings or field tuples (optional)) – The name of the field(s) that we want to show the axes.

show_colorbar(field=None)

Shows the colorbar for a plot and updates the size of the plot accordingly. Defaults to operating on all fields for a PlotContainer object. See hide_colorbar().

Parameters
• field (string, field tuple, or list of strings or field tuples (optional)) –

• name of the field(s) that we want to show the colorbar. (The) –

to_fits_data(fields=None, other_keys=None, length_unit=None, **kwargs)

Export the fields in this PlotWindow instance to a FITSImageData instance.

This will export a set of FITS images of either the fields specified or all the fields already in the object.

Parameters
• fields (list of strings) – These fields will be pixelized and output. If “None”, the keys of the FRB will be used.

• other_keys (dictionary, optional) – A set of header keys and values to write into the FITS header.

• length_unit (string, optional) – the length units that the coordinates are written in. The default is to use the default length unit of the dataset.

toggle_right_handed()
property width
zoom(factor)

This zooms the window by factor > 0. - zoom out with factor < 1 - zoom in with factor > 1

Parameters

factor (float) – multiplier for the current width

yt.visualization.plot_window.SlicePlot(ds, normal=None, fields=None, axis=None, *args, **kwargs)[source]

A factory function for yt.visualization.plot_window.AxisAlignedSlicePlot and yt.visualization.plot_window.OffAxisSlicePlot objects. This essentially allows for a single entry point to both types of slice plots, the distinction being determined by the specified normal vector to the slice.

The returned plot object can be updated using one of the many helper functions defined in PlotWindow.

Parameters
• ds (yt.data_objects.static_output.Dataset) – This is the dataset object corresponding to the simulation output to be plotted.

• normal (int or one of 'x', 'y', 'z', or sequence of floats) – This specifies the normal vector to the slice. If given as an integer or a coordinate string (0=x, 1=y, 2=z), this function will return an AxisAlignedSlicePlot object. If given as a sequence of floats, this is interpreted as an off-axis vector and an OffAxisSlicePlot object is returned.

• fields (string) – The name of the field(s) to be plotted.

• axis (int or one of 'x', 'y', 'z') – An int corresponding to the axis to slice along (0=x, 1=y, 2=z) or the axis name itself. If specified, this will replace normal.

The following are nominally keyword arguments passed onto the respective slice plot objects generated by this function.

Keyword Arguments
• center (A sequence floats, a string, or a tuple.) – The coordinate of the center of the image. If set to ‘c’, ‘center’ or left blank, the plot is centered on the middle of the domain. If set to ‘max’ or ‘m’, the center will be located at the maximum of the (‘gas’, ‘density’) field. Centering on the max or min of a specific field is supported by providing a tuple such as (“min”,”temperature”) or (“max”,”dark_matter_density”). Units can be specified by passing in center as a tuple containing a coordinate and string unit name or by passing in a YTArray. If a list or unitless array is supplied, code units are assumed.

• width (tuple or a float.) –

Width can have four different formats to support windows with variable x and y widths. They are:

format

example

(float, string)

(10,’kpc’)

((float, string), (float, string))

((10,’kpc’),(15,’kpc’))

float

0.2

(float, float)

(0.2, 0.3)

For example, (10, ‘kpc’) requests a plot window that is 10 kiloparsecs wide in the x and y directions, ((10,’kpc’),(15,’kpc’)) requests a window that is 10 kiloparsecs wide along the x axis and 15 kiloparsecs wide along the y axis. In the other two examples, code units are assumed, for example (0.2, 0.3) requests a plot that has an x width of 0.2 and a y width of 0.3 in code units. If units are provided the resulting plot axis labels will use the supplied units.

• axes_unit (string) – The name of the unit for the tick labels on the x and y axes. Defaults to None, which automatically picks an appropriate unit. If axes_unit is ‘1’, ‘u’, or ‘unitary’, it will not display the units, and only show the axes name.

• origin (string or length 1, 2, or 3 sequence.) –

The location of the origin of the plot coordinate system for AxisAlignedSlicePlot object; for OffAxisSlicePlot objects this parameter is discarded. This is typically represented by a ‘-‘ separated string or a tuple of strings. In the first index the y-location is given by ‘lower’, ‘upper’, or ‘center’. The second index is the x-location, given as ‘left’, ‘right’, or ‘center’. Finally, the whether the origin is applied in ‘domain’ space, plot ‘window’ space or ‘native’ simulation coordinate system is given. For example, both ‘upper-right-domain’ and [‘upper’, ‘right’, ‘domain’] place the origin in the upper right hand corner of domain space. If x or y are not given, a value is inferred. For instance, ‘left-domain’ corresponds to the lower-left hand corner of the simulation domain, ‘center-domain’ corresponds to the center of the simulation domain, or ‘center-window’ for the center of the plot window. In the event that none of these options place the origin in a desired location, a sequence of tuples and a string specifying the coordinate space can be given. If plain numeric types are input, units of code_length are assumed. Further examples:

format

example

’{space}’

’domain’

’{xloc}-{space}’

’left-window’

’{yloc}-{space}’

’upper-domain’

’{yloc}-{xloc}-{space}’

’lower-right-window’

(‘{space}’,)

(‘window’,)

(‘{xloc}’, ‘{space}’)

(‘right’, ‘domain’)

(‘{yloc}’, ‘{space}’)

(‘lower’, ‘window’)

(‘{yloc}’, ‘{xloc}’, ‘{space}’)

(‘lower’, ‘right’, ‘window’)

((yloc, ‘{unit}’), (xloc, ‘{unit}’), ‘{space}’)

((0, ‘m’), (.4, ‘m’), ‘window’)

(xloc, yloc, ‘{space}’)

(0.23, 0.5, ‘domain’)

• north_vector (a sequence of floats) – A vector defining the ‘up’ direction in the OffAxisSlicePlot; not used in AxisAlignedSlicePlot. This option sets the orientation of the slicing plane. If not set, an arbitrary grid-aligned north-vector is chosen.

• fontsize (integer) – The size of the fonts for the axis, colorbar, and tick labels.

• field_parameters (dictionary) – A dictionary of field parameters than can be accessed by derived fields.

• data_source (YTSelectionContainer Object) – Object to be used for data selection. Defaults to a region covering the entire simulation.

Raises

AssertionError – If a proper normal axis is not specified via the normal or axis keywords, and/or if a field to plot is not specified.

Examples

>>> from yt import load
>>> ds = load("IsolatedGalaxy/galaxy0030/galaxy0030")
>>> slc = SlicePlot(ds, "x", ("gas", "density"), center=[0.2, 0.3, 0.4])

>>> slc = SlicePlot(
...     ds, [0.4, 0.2, -0.1], ("gas", "pressure"), north_vector=[0.2, -0.3, 0.1]
... )

class yt.visualization.plot_window.WindowPlotMPL(data, cbname, cblinthresh, cmap, extent, zlim, figure_size, fontsize, aspect, figure, axes, cax, mpl_proj, mpl_transform)[source]

A container for a single PlotWindow matplotlib figure and axes

hide_axes(draw_frame=None)

Hide the axes for a plot including ticks and labels

hide_colorbar()

Hide the colorbar for a plot including ticks and labels

save(name, mpl_kwargs=None, canvas=None)

Choose backend and save image to disk

show()
show_axes()

Show the axes for a plot including ticks and labels

show_colorbar()

Show the colorbar for a plot including ticks and labels

yt.visualization.plot_window.get_axes_unit(width, ds)[source]

Infers the axes unit names from the input width specification

yt.visualization.plot_window.get_oblique_window_parameters(normal, center, width, ds, depth=None)[source]
yt.visualization.plot_window.get_window_parameters(axis, center, width, ds)[source]
yt.visualization.plot_window.plot_2d(ds, fields, center='c', width=None, axes_unit=None, origin='center-window', fontsize=18, field_parameters=None, window_size=8.0, aspect=None, data_source=None)[source]

Creates a plot of a 2D dataset

Given a ds object and a field name string, this will return a PWViewerMPL object containing the plot.

The plot can be updated using one of the many helper functions defined in PlotWindow.

Parameters
• ds (Dataset) – This is the dataset object corresponding to the simulation output to be plotted.

• fields (string) – The name of the field(s) to be plotted.

• center (A sequence of floats, a string, or a tuple.) – The coordinate of the center of the image. If set to ‘c’, ‘center’ or left blank, the plot is centered on the middle of the domain. If set to ‘max’ or ‘m’, the center will be located at the maximum of the (‘gas’, ‘density’) field. Centering on the max or min of a specific field is supported by providing a tuple such as (“min”,”temperature”) or (“max”,”dark_matter_density”). Units can be specified by passing in center as a tuple containing a coordinate and string unit name or by passing in a YTArray. If a list or unitless array is supplied, code units are assumed. For plot_2d, this keyword accepts a coordinate in two dimensions.

• width (tuple or a float.) –

Width can have four different formats to support windows with variable x and y widths. They are:

format

example

(float, string)

(10,’kpc’)

((float, string), (float, string))

((10,’kpc’),(15,’kpc’))

float

0.2

(float, float)

(0.2, 0.3)

For example, (10, ‘kpc’) requests a plot window that is 10 kiloparsecs wide in the x and y directions, ((10,’kpc’),(15,’kpc’)) requests a window that is 10 kiloparsecs wide along the x axis and 15 kiloparsecs wide along the y axis. In the other two examples, code units are assumed, for example (0.2, 0.3) requests a plot that has an x width of 0.2 and a y width of 0.3 in code units. If units are provided the resulting plot axis labels will use the supplied units.

• origin (string or length 1, 2, or 3 sequence.) –

The location of the origin of the plot coordinate system. This is typically represented by a ‘-‘ separated string or a tuple of strings. In the first index the y-location is given by ‘lower’, ‘upper’, or ‘center’. The second index is the x-location, given as ‘left’, ‘right’, or ‘center’. Finally, whether the origin is applied in ‘domain’ space, plot ‘window’ space or ‘native’ simulation coordinate system is given. For example, both ‘upper-right-domain’ and [‘upper’, ‘right’, ‘domain’] place the origin in the upper right hand corner of domain space. If x or y are not given, a value is inferred. For instance, ‘left-domain’ corresponds to the lower-left hand corner of the simulation domain, ‘center-domain’ corresponds to the center of the simulation domain, or ‘center-window’ for the center of the plot window. In the event that none of these options place the origin in a desired location, a sequence of tuples and a string specifying the coordinate space can be given. If plain numeric types are input, units of code_length are assumed. Further examples:

format

example

’{space}’

’domain’

’{xloc}-{space}’

’left-window’

’{yloc}-{space}’

’upper-domain’

’{yloc}-{xloc}-{space}’

’lower-right-window’

(‘{space}’,)

(‘window’,)

(‘{xloc}’, ‘{space}’)

(‘right’, ‘domain’)

(‘{yloc}’, ‘{space}’)

(‘lower’, ‘window’)

(‘{yloc}’, ‘{xloc}’, ‘{space}’)

(‘lower’, ‘right’, ‘window’)

((yloc, ‘{unit}’), (xloc, ‘{unit}’), ‘{space}’)

((0, ‘m’), (.4, ‘m’), ‘window’)

(xloc, yloc, ‘{space}’)

(0.23, 0.5, ‘domain’)

• axes_unit (string) – The name of the unit for the tick labels on the x and y axes. Defaults to None, which automatically picks an appropriate unit. If axes_unit is ‘1’, ‘u’, or ‘unitary’, it will not display the units, and only show the axes name.

• fontsize (integer) – The size of the fonts for the axis, colorbar, and tick labels.

• field_parameters (dictionary) – A dictionary of field parameters than can be accessed by derived fields.

• data_source (YTSelectionContainer object) – Object to be used for data selection. Defaults to ds.all_data(), a region covering the full domain

yt.visualization.plot_window.validate_mesh_fields(data_source, fields)[source]