yt.visualization.plot_window module

A plotting mechanism based on the idea of a “window” into the data.

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)[source]

Bases: yt.visualization.plot_window.PWViewerMPL

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.5, ‘m’), (0.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

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.)

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.

frb

The frb property.

get_log(field)

get the transform type of a field.

Parameters:field (string) – the field to get a transform
hide_axes(field=None)

Hides the axes for a plot and updates the size of the plot accordingly. Defaults to operating on all fields for a PlotWindow 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.

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()
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 PlotWindow 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 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)

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=None, mpl_kwargs=None)

saves the plot to disk.

Parameters:
  • name (string) – The base of the filename. If name is a directory or if name is not set, the filename of the dataset is used.
  • 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)
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

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

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("density", "Dark Matter Density (g cm$^{-3}$)") (>>>) –
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. http://matplotlib.org/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)

set a field to log or linear.

Parameters:
  • field (string) – the field to set a transform
  • log (boolean) – Log on/off.
  • linthresh (float (must be positive)) – linthresh will be enabled for symlog scale only when log is true
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’, ‘off’) if drawing speed is a problem.

Parameters:
  • field (string) – the field to remove minorticks
  • state (string) – the state indicating ‘on’ or ‘off’
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:
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.5, ‘m’), (0.4, ‘m’), ‘window’)
(xloc, yloc, ‘{space}’) (0.23, 0.5, ‘domain’)
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 equivelancy
  • 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.

This is equivalent to set_figure_size but it still available to maintain backwards compatibility.

set_xlabel(label)

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

Parameters:
  • x_title (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) – the new minimum of the colormap scale. If ‘min’, will set to the minimum value in the current view.
  • zmax (float) – 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()
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", ["Density", "VelocityMagnitude"])
>>> 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 PlotWindow 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 PlotWindow object. See hide_colorbar().

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 colorbar.
toggle_right_handed()
width
zoom(factor)

This zooms the window by factor.

Parameters:factor (float) – multiplier for the current width
class yt.visualization.plot_window.OffAxisProjectionDummyDataSource(center, ds, normal_vector, width, fields, interpolated, resolution=(800, 800), 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)[source]

Bases: yt.visualization.plot_window.PWViewerMPL

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
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.)

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.

frb

The frb property.

get_log(field)

get the transform type of a field.

Parameters:field (string) – the field to get a transform
hide_axes(field=None)

Hides the axes for a plot and updates the size of the plot accordingly. Defaults to operating on all fields for a PlotWindow 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.

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()
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 PlotWindow 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 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)

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=None, mpl_kwargs=None)

saves the plot to disk.

Parameters:
  • name (string) – The base of the filename. If name is a directory or if name is not set, the filename of the dataset is used.
  • 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)
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

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

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("density", "Dark Matter Density (g cm$^{-3}$)") (>>>) –
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. http://matplotlib.org/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)

set a field to log or linear.

Parameters:
  • field (string) – the field to set a transform
  • log (boolean) – Log on/off.
  • linthresh (float (must be positive)) – linthresh will be enabled for symlog scale only when log is true
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’, ‘off’) if drawing speed is a problem.

Parameters:
  • field (string) – the field to remove minorticks
  • state (string) – the state indicating ‘on’ or ‘off’
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:
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.5, ‘m’), (0.4, ‘m’), ‘window’)
(xloc, yloc, ‘{space}’) (0.23, 0.5, ‘domain’)
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 equivelancy
  • 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.

This is equivalent to set_figure_size but it still available to maintain backwards compatibility.

set_xlabel(label)

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

Parameters:
  • x_title (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) – the new minimum of the colormap scale. If ‘min’, will set to the minimum value in the current view.
  • zmax (float) – 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()
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", ["Density", "VelocityMagnitude"])
>>> 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 PlotWindow 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 PlotWindow object. See hide_colorbar().

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 colorbar.
toggle_right_handed()
width
zoom(factor)

This zooms the window by factor.

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)[source]

Bases: yt.visualization.plot_window.PWViewerMPL

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.
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.)

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.

frb

The frb property.

get_log(field)

get the transform type of a field.

Parameters:field (string) – the field to get a transform
hide_axes(field=None)

Hides the axes for a plot and updates the size of the plot accordingly. Defaults to operating on all fields for a PlotWindow 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.

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()
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 PlotWindow 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 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)

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=None, mpl_kwargs=None)

saves the plot to disk.

Parameters:
  • name (string) – The base of the filename. If name is a directory or if name is not set, the filename of the dataset is used.
  • 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)
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

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

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("density", "Dark Matter Density (g cm$^{-3}$)") (>>>) –
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. http://matplotlib.org/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)

set a field to log or linear.

Parameters:
  • field (string) – the field to set a transform
  • log (boolean) – Log on/off.
  • linthresh (float (must be positive)) – linthresh will be enabled for symlog scale only when log is true
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’, ‘off’) if drawing speed is a problem.

Parameters:
  • field (string) – the field to remove minorticks
  • state (string) – the state indicating ‘on’ or ‘off’
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:
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.5, ‘m’), (0.4, ‘m’), ‘window’)
(xloc, yloc, ‘{space}’) (0.23, 0.5, ‘domain’)
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 equivelancy
  • 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.

This is equivalent to set_figure_size but it still available to maintain backwards compatibility.

set_xlabel(label)

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

Parameters:
  • x_title (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) – the new minimum of the colormap scale. If ‘min’, will set to the minimum value in the current view.
  • zmax (float) – 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()
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", ["Density", "VelocityMagnitude"])
>>> 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 PlotWindow 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 PlotWindow object. See hide_colorbar().

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 colorbar.
toggle_right_handed()
width
zoom(factor)

This zooms the window by factor.

Parameters:factor (float) – multiplier for the current width
class yt.visualization.plot_window.PWViewerMPL(*args, **kwargs)[source]

Bases: yt.visualization.plot_window.PlotWindow

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.)

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.

frb

The frb property.

get_log(field)

get the transform type of a field.

Parameters:field (string) – the field to get a transform
hide_axes(field=None)[source]

Hides the axes for a plot and updates the size of the plot accordingly. Defaults to operating on all fields for a PlotWindow 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.

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()
hide_colorbar(field=None)[source]

Hides the colorbar for a plot and updates the size of the plot accordingly. Defaults to operating on all fields for a PlotWindow 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 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)

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=None, mpl_kwargs=None)

saves the plot to disk.

Parameters:
  • name (string) – The base of the filename. If name is a directory or if name is not set, the filename of the dataset is used.
  • 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)
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

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

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("density", "Dark Matter Density (g cm$^{-3}$)") (>>>) –
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. http://matplotlib.org/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)

set a field to log or linear.

Parameters:
  • field (string) – the field to set a transform
  • log (boolean) – Log on/off.
  • linthresh (float (must be positive)) – linthresh will be enabled for symlog scale only when log is true
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’, ‘off’) if drawing speed is a problem.

Parameters:
  • field (string) – the field to remove minorticks
  • state (string) – the state indicating ‘on’ or ‘off’
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:
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.5, ‘m’), (0.4, ‘m’), ‘window’)
(xloc, yloc, ‘{space}’) (0.23, 0.5, ‘domain’)
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 equivelancy
  • 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.

This is equivalent to set_figure_size but it still available to maintain backwards compatibility.

set_xlabel(label)

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

Parameters:
  • x_title (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) – the new minimum of the colormap scale. If ‘min’, will set to the minimum value in the current view.
  • zmax (float) – 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]
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", ["Density", "VelocityMagnitude"])
>>> slc.show()
show_axes(field=None)[source]

Shows the axes for a plot and updates the size of the plot accordingly. Defaults to operating on all fields for a PlotWindow 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)[source]

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

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 colorbar.
toggle_right_handed()
width
zoom(factor)

This zooms the window by factor.

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]

Bases: yt.visualization.plot_container.ImagePlotContainer

A ploting 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_source (subclass of yt.data_objects.selection_data_containers.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.
  • window_size – 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.
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.

frb

The frb property.

get_log(field)

get the transform type of a field.

Parameters:field (string) – the field to get a transform
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=None, mpl_kwargs=None)

saves the plot to disk.

Parameters:
  • name (string) – The base of the filename. If name is a directory or if name is not set, the filename of the dataset is used.
  • 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]
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

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

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("density", "Dark Matter Density (g cm$^{-3}$)") (>>>) –
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. http://matplotlib.org/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)

set a field to log or linear.

Parameters:
  • field (string) – the field to set a transform
  • log (boolean) – Log on/off.
  • linthresh (float (must be positive)) – linthresh will be enabled for symlog scale only when log is true
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’, ‘off’) if drawing speed is a problem.

Parameters:
  • field (string) – the field to remove minorticks
  • state (string) – the state indicating ‘on’ or ‘off’
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:
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.5, ‘m’), (0.4, ‘m’), ‘window’)
(xloc, yloc, ‘{space}’) (0.23, 0.5, ‘domain’)
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 equivelancy
  • 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.

This is equivalent to set_figure_size but it still available to maintain backwards compatibility.

set_xlabel(label)

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

Parameters:
  • x_title (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) – the new minimum of the colormap scale. If ‘min’, will set to the minimum value in the current view.
  • zmax (float) – 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.

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", ["Density", "VelocityMagnitude"])
>>> slc.show()
toggle_right_handed()[source]
width
zoom(factor)[source]

This zooms the window by factor.

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, aspect=None)[source]

Bases: yt.visualization.plot_window.PWViewerMPL

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.5, ‘m’), (0.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

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", "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.)

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.

frb

The frb property.

get_log(field)

get the transform type of a field.

Parameters:field (string) – the field to get a transform
hide_axes(field=None)

Hides the axes for a plot and updates the size of the plot accordingly. Defaults to operating on all fields for a PlotWindow 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.

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()
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 PlotWindow 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 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)

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=None, mpl_kwargs=None)

saves the plot to disk.

Parameters:
  • name (string) – The base of the filename. If name is a directory or if name is not set, the filename of the dataset is used.
  • 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)
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

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

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("density", "Dark Matter Density (g cm$^{-3}$)") (>>>) –
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. http://matplotlib.org/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)

set a field to log or linear.

Parameters:
  • field (string) – the field to set a transform
  • log (boolean) – Log on/off.
  • linthresh (float (must be positive)) – linthresh will be enabled for symlog scale only when log is true
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’, ‘off’) if drawing speed is a problem.

Parameters:
  • field (string) – the field to remove minorticks
  • state (string) – the state indicating ‘on’ or ‘off’
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:
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.5, ‘m’), (0.4, ‘m’), ‘window’)
(xloc, yloc, ‘{space}’) (0.23, 0.5, ‘domain’)
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 equivelancy
  • 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.

This is equivalent to set_figure_size but it still available to maintain backwards compatibility.

set_xlabel(label)

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

Parameters:
  • x_title (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) – the new minimum of the colormap scale. If ‘min’, will set to the minimum value in the current view.
  • zmax (float) – 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()
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", ["Density", "VelocityMagnitude"])
>>> 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 PlotWindow 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 PlotWindow object. See hide_colorbar().

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 colorbar.
toggle_right_handed()
width
zoom(factor)

This zooms the window by factor.

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 interpretted 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.
  • following are nominally keyword arguments passed onto the respective (The) –
  • plot objects generated by this function. (slice) –
  • 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.5, ‘m’), (0.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", "density", center=[0.2,0.3,0.4])
>>>
>>> slc = SlicePlot(ds, [0.4, 0.2, -0.1], "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)[source]

Bases: yt.visualization.base_plot_types.ImagePlotMPL

A container for a single PlotWindow matplotlib figure and axes

hide_axes()

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.5, ‘m’), (0.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]