yt.visualization.plot_container module

class yt.visualization.plot_container.FieldTransform(name, func)[source]

Bases: object

class yt.visualization.plot_container.ImagePlotContainer(data_source, figure_size, fontsize)[source]

Bases: yt.visualization.plot_container.PlotContainer

A container for plots with colorbars.

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.

get_log(field)

get the transform type of a field.

Parameters

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

hide_axes(field=None, draw_frame=False)

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

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

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

Examples

This will save an image with no axes.

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

This will save an image with no axis or colorbar.

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

Note

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

hide_colorbar(field=None)

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

Parameters

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

Examples

This will save an image with no colorbar.

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

This will save an image with no axis or colorbar.

>>> import yt
>>> ds = yt.load("IsolatedGalaxy/galaxy0030/galaxy0030")
>>> s = SlicePlot(ds, 2, "density", "c", (20, "kpc"))
>>> s.hide_axes()
>>> s.hide_colorbar()
>>> s.save()
refresh()
save(name=None, suffix='.png', mpl_kwargs=None)

saves the plot to disk.

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

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

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

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

set_background_color(field, color=None)[source]

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_cbar_minorticks(field, state)[source]

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

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

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

set_cmap(field, cmap)[source]

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

Sets the colorbar label.

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

  • label (str) – The new label

  • plot.set_colorbar_label( (>>>) –

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

  • ) (..) –

set_colorbar_minorticks(field, state)[source]

turn colorbar minor ticks on or off in the current plot

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

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

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

set_figure_size(size)

Sets a new figure size for the plot

Parameters

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

set_font(font_dict=None)

Set the font and font properties.

Parameters

font_dict (dict) –

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

Possible keys include:

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

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

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

  • variant - Either normal or small-caps.

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

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

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

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

Notes

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

Examples

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

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

Set the size of the font used in the plot

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

Parameters
  • size (float) –

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

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

set a field to log, linear, or symlog.

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

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

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

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

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

set_minorticks(field, state)

Turn minor ticks on or off in the current plot.

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

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

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

set_transform(field, name)
set_xlabel(label)

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

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

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

set_ylabel(label)

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

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

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

set_zlim(field, zmin, zmax, dynamic_range=None)[source]

set the scale of the colormap

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

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

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

Other Parameters

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

setup_defaults()
show()

This will send any existing plots to the IPython notebook.

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

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

Examples

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

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

Parameters

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

show_colorbar(field=None)

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

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

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

class yt.visualization.plot_container.PlotContainer(data_source, figure_size, fontsize)[source]

Bases: object

A container for generic plots

display(name=None, mpl_kwargs=None)[source]

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

get_log(field)[source]

get the transform type of a field.

Parameters

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

hide_axes(field=None, draw_frame=False)[source]

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

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

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

Examples

This will save an image with no axes.

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

This will save an image with no axis or colorbar.

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

Note

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

hide_colorbar(field=None)[source]

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

Parameters

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

Examples

This will save an image with no colorbar.

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

This will save an image with no axis or colorbar.

>>> import yt
>>> ds = yt.load("IsolatedGalaxy/galaxy0030/galaxy0030")
>>> s = SlicePlot(ds, 2, "density", "c", (20, "kpc"))
>>> s.hide_axes()
>>> s.hide_colorbar()
>>> s.save()
refresh()[source]
save(name=None, suffix='.png', mpl_kwargs=None)[source]

saves the plot to disk.

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

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

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

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

set_figure_size(size)[source]

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

Set the font and font properties.

Parameters

font_dict (dict) –

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

Possible keys include:

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

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

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

  • variant - Either normal or small-caps.

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

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

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

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

Notes

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

Examples

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

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

Set the size of the font used in the plot

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

Parameters
  • size (float) –

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

set_log(field, log, linthresh=None, symlog_auto=False)[source]

set a field to log, linear, or symlog.

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

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

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

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

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

set_minorticks(field, state)[source]

Turn minor ticks on or off in the current plot.

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

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

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

set_transform(field, name)[source]
set_xlabel(label)[source]

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

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

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

set_ylabel(label)[source]

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)") (>>>) –

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

This will send any existing plots to the IPython notebook.

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

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

Examples

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

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

Parameters

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

show_colorbar(field=None)[source]

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

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

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

class yt.visualization.plot_container.PlotDictionary(data_source, default_factory=None)[source]

Bases: collections.defaultdict

clear() → None. Remove all items from D.
copy() → a shallow copy of D.
default_factory

Factory for default value called by __missing__().

fromkeys(value=None, /)

Create a new dictionary with keys from iterable and values set to value.

get(key, default=None, /)

Return the value for key if key is in the dictionary, else default.

items() → a set-like object providing a view on D’s items
keys() → a set-like object providing a view on D’s keys
pop(k[, d]) → v, remove specified key and return the corresponding value.

If key is not found, d is returned if given, otherwise KeyError is raised

popitem()

Remove and return a (key, value) pair as a 2-tuple.

Pairs are returned in LIFO (last-in, first-out) order. Raises KeyError if the dict is empty.

setdefault(key, default=None, /)

Insert key with a value of default if key is not in the dictionary.

Return the value for key if key is in the dictionary, else default.

update([E, ]**F) → None. Update D from dict/iterable E and F.

If E is present and has a .keys() method, then does: for k in E: D[k] = E[k] If E is present and lacks a .keys() method, then does: for k, v in E: D[k] = v In either case, this is followed by: for k in F: D[k] = F[k]

values() → an object providing a view on D’s values
yt.visualization.plot_container.accepts_all_fields(func)[source]

Decorate a function whose second argument is <field> and deal with the special case field == ‘all’, looping over all fields already present in the PlotContainer object.

yt.visualization.plot_container.apply_callback(f)[source]
yt.visualization.plot_container.get_log_minorticks(vmin, vmax)[source]

calculate positions of linear minorticks on a log colorbar

Parameters
  • vmin (float) – the minimum value in the colorbar

  • vmax (float) – the maximum value in the colorbar

yt.visualization.plot_container.get_symlog_minorticks(linthresh, vmin, vmax)[source]

calculate positions of linear minorticks on a symmetric log colorbar

Parameters
  • linthresh (float) – the threshold for the linear region

  • vmin (float) – the minimum value in the colorbar

  • vmax (float) – the maximum value in the colorbar

yt.visualization.plot_container.invalidate_data(f)[source]
yt.visualization.plot_container.invalidate_figure(f)[source]
yt.visualization.plot_container.invalidate_plot(f)[source]
yt.visualization.plot_container.validate_plot(f)[source]