yt.visualization.plot_container module

class yt.visualization.plot_container.BaseLinePlot(data_source, figure_size=None, fontsize: float | None = None)[source]

Bases: PlotContainer, ABC

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

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()
render() None

Render plots. This operation is expensive and usually doesn’t need to be requested explicitly. In most cases, yt handles rendering automatically and delays it as much as possible to avoid redundant calls on each plot modification (e.g. via annotate_* methods).

However, valid use cases of this method include: - fine control of render (and clear) operations when yt plots are combined with plot

customizations other than plot callbacks (annotate_*)

  • testing

save(name: str | list[str] | tuple[str, ...] | None = None, suffix: str | None = None, mpl_kwargs: dict[str, Any] | None = None)

saves the plot to disk.

Parameters:
  • name (string or tuple, optional) – 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, optional) – 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, optional) – A dict of keyword arguments to be passed to matplotlib.

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

set_figure_size(size)

Sets a new figure size for the plot

Parameters:

size (float, a sequence of two floats, or None) – The size of the figure (in units of inches), including the margins but not the colorbar. If a single float is passed, it’s interpreted as the size along the long axis. Pass None to reset

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)

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

set_log(field, log: bool | None = None, *, linthresh: float | unyt_quantity | tuple[float, Unit | str] | Literal['auto'] | None = None, symlog_auto: bool | None = None)

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 value for linthresh.

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

  • log (boolean, optional) – set log to True for log scaling, False for linear scaling.

  • linthresh (float, (float, str), unyt_quantity, or 'auto', 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

  • arguments (Note that log and linthresh are mutually exclusive)

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_norm(field, norm: Normalize)

Set a custom matplotlib.colors.Normalize to plot field.

Any constraints previously set with set_log, set_zlim will be dropped.

Note that any float value attached to norm (e.g. vmin, vmax, vcenter …) will be read in the current displayed units, which can be controlled with the set_unit method.

Parameters:
set_transform(field, name: str)
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.

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

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.

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

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

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

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

Bases: PlotContainer, ABC

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

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()
render() None

Render plots. This operation is expensive and usually doesn’t need to be requested explicitly. In most cases, yt handles rendering automatically and delays it as much as possible to avoid redundant calls on each plot modification (e.g. via annotate_* methods).

However, valid use cases of this method include: - fine control of render (and clear) operations when yt plots are combined with plot

customizations other than plot callbacks (annotate_*)

  • testing

save(name: str | list[str] | tuple[str, ...] | None = None, suffix: str | None = None, mpl_kwargs: dict[str, Any] | None = None)

saves the plot to disk.

Parameters:
  • name (string or tuple, optional) – 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, optional) – 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, optional) – 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_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")

  • cm$^{-3}$)" ("Dark Matter Density (g)

  • ) (...)

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, a sequence of two floats, or None) – The size of the figure (in units of inches), including the margins but not the colorbar. If a single float is passed, it’s interpreted as the size along the long axis. Pass None to reset

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)

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

set_log(field, log: bool | None = None, *, linthresh: float | unyt_quantity | tuple[float, Unit | str] | Literal['auto'] | None = None, symlog_auto: bool | None = None)

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 value for linthresh.

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

  • log (boolean, optional) – set log to True for log scaling, False for linear scaling.

  • linthresh (float, (float, str), unyt_quantity, or 'auto', 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

  • arguments (Note that log and linthresh are mutually exclusive)

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_norm(field, norm: Normalize)

Set a custom matplotlib.colors.Normalize to plot field.

Any constraints previously set with set_log, set_zlim will be dropped.

Note that any float value attached to norm (e.g. vmin, vmax, vcenter …) will be read in the current displayed units, which can be controlled with the set_unit method.

Parameters:
set_transform(field, name: str)
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.

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

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.

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

set_zlim(field, zmin: ~unyt.array.unyt_quantity | tuple[float, ~unyt.unit_object.Unit | str] | float | ~typing.Literal['min'] | ~yt.visualization.plot_container.Unset = <yt.visualization.plot_container.Unset object>, zmax: ~unyt.array.unyt_quantity | tuple[float, ~unyt.unit_object.Unit | str] | float | ~typing.Literal['max'] | ~yt.visualization.plot_container.Unset = <yt.visualization.plot_container.Unset object>, dynamic_range: float | None = 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, Quantity, or 'min') – the new minimum of the colormap scale. If ‘min’, will set to the minimum value in the current view.

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

  • 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

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

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

class yt.visualization.plot_container.PlotContainer(data_source, figure_size=None, fontsize: float | None = None)[source]

Bases: ABC

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

Render plots. This operation is expensive and usually doesn’t need to be requested explicitly. In most cases, yt handles rendering automatically and delays it as much as possible to avoid redundant calls on each plot modification (e.g. via annotate_* methods).

However, valid use cases of this method include: - fine control of render (and clear) operations when yt plots are combined with plot

customizations other than plot callbacks (annotate_*)

  • testing

save(name: str | list[str] | tuple[str, ...] | None = None, suffix: str | None = None, mpl_kwargs: dict[str, Any] | None = None)[source]

saves the plot to disk.

Parameters:
  • name (string or tuple, optional) – 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, optional) – 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, optional) – 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, a sequence of two floats, or None) – The size of the figure (in units of inches), including the margins but not the colorbar. If a single float is passed, it’s interpreted as the size along the long axis. Pass None to reset

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)

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

set_log(field, log: bool | None = None, *, linthresh: float | unyt_quantity | tuple[float, Unit | str] | Literal['auto'] | None = None, symlog_auto: bool | None = None)[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 value for linthresh.

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

  • log (boolean, optional) – set log to True for log scaling, False for linear scaling.

  • linthresh (float, (float, str), unyt_quantity, or 'auto', 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

  • arguments (Note that log and linthresh are mutually exclusive)

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_norm(field, norm: Normalize)[source]

Set a custom matplotlib.colors.Normalize to plot field.

Any constraints previously set with set_log, set_zlim will be dropped.

Note that any float value attached to norm (e.g. vmin, vmax, vcenter …) will be read in the current displayed units, which can be controlled with the set_unit method.

Parameters:
set_transform(field, name: str)[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.

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

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.

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

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

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

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

Bases: 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 the key is not found, return the default if given; otherwise, raise a KeyError.

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
class yt.visualization.plot_container.Unset[source]

Bases: object

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]