yt.visualization.profile_plotter module

class yt.visualization.profile_plotter.PhasePlot(data_source, x_field, y_field, z_fields, weight_field=('gas', 'mass'), x_bins=128, y_bins=128, accumulation=False, fractional=False, fontsize=18, figure_size=8.0, shading='nearest')[source]

Bases: ImagePlotContainer

Create a 2d profile (phase) plot from a data source or from profile object created with yt.data_objects.profiles.create_profile.

Given a data object (all_data, region, sphere, etc.), an x field, y field, and z field (or fields), this will create a two-dimensional profile of the average (or total) value of the z field in bins of the x and y fields.

Parameters:
  • data_source (YTSelectionContainer Object) – The data object to be profiled, such as all_data, region, or sphere. If a dataset is passed in instead, an all_data data object is generated internally from the dataset.

  • x_field (str) – The x binning field for the profile.

  • y_field (str) – The y binning field for the profile.

  • z_fields (str or list) – The field or fields to be profiled.

  • weight_field (str) – The weight field for calculating weighted averages. If None, the profile values are the sum of the field values within the bin. Otherwise, the values are a weighted average. Default : (“gas”, “mass”)

  • x_bins (int) – The number of bins in x field for the profile. Default: 128.

  • y_bins (int) – The number of bins in y field for the profile. Default: 128.

  • accumulation (bool or list of bools) – If True, the profile values for a bin n are the cumulative sum of all the values from bin 0 to n. If -True, the sum is reversed so that the value for bin n is the cumulative sum from bin N (total bins) to n. A list of values can be given to control the summation in each dimension independently. Default: False.

  • fractional (If True the profile values are divided by the sum of all) – the profile data such that the profile represents a probability distribution function.

  • fontsize (int) – Font size for all text in the plot. Default: 18.

  • figure_size (int) – Size in inches of the image. Default: 8 (8x8)

  • shading (str) – This argument is directly passed down to matplotlib.axes.Axes.pcolormesh see https://matplotlib.org/3.3.1/gallery/images_contours_and_fields/pcolormesh_grids.html#sphx-glr-gallery-images-contours-and-fields-pcolormesh-grids-py # noqa Default: ‘nearest’

Examples

>>> import yt
>>> ds = yt.load("enzo_tiny_cosmology/DD0046/DD0046")
>>> ad = ds.all_data()
>>> plot = yt.PhasePlot(
...     ad,
...     ("gas", "density"),
...     ("gas", "temperature"),
...     [("gas", "mass")],
...     weight_field=None,
... )
>>> plot.save()
>>> # Change plot properties.
>>> plot.set_cmap(("gas", "mass"), "jet")
>>> plot.set_zlim(("gas", "mass"), 1e8, 1e13)
>>> plot.annotate_title("This is a phase plot")
annotate_text(xpos=0.0, ypos=0.0, text=None, **text_kwargs)[source]

Allow the user to insert text onto the plot The x-position and y-position must be given as well as the text string. Add text tp plot at location xpos, ypos in plot coordinates (see example below).

Parameters:
  • xpos (float) – Position on plot in x-coordinates.

  • ypos (float) – Position on plot in y-coordinates.

  • text (str) – The text to insert onto the plot.

  • **text_kwargs (dict) – Extra keyword arguments will be passed to matplotlib text instance

  • plot.annotate_text(1e-15 (>>>) –

  • 5e4

  • YT") ("Hello) –

annotate_title(title)[source]

Set a title for the plot.

Parameters:

title (str) – The title to add.

Examples

>>> plot.annotate_title("This is a phase plot")
display(name=None, mpl_kwargs=None)

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

property fields
classmethod from_profile(profile, fontsize=18, figure_size=8.0, shading='nearest')[source]

Instantiate a PhasePlot object from a profile object created with create_profile().

Parameters:

Examples

>>> import yt
>>> ds = yt.load("IsolatedGalaxy/galaxy0030/galaxy0030")
>>> extrema = {
...     ("gas", "density"): (1e-31, 1e-24),
...     ("gas", "temperature"): (1e1, 1e8),
...     ("gas", "mass"): (1e-6, 1e-1),
... }
>>> profile = yt.create_profile(
...     ds.all_data(),
...     [("gas", "density"), ("gas", "temperature")],
...     fields=[("gas", "mass")],
...     extrema=extrema,
...     fractional=True,
... )
>>> ph = yt.PhasePlot.from_profile(profile)
>>> ph.save()
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()
plot_title = None
property profile
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

reset_plot()[source]
save(name: str | None = None, suffix: str | None = None, mpl_kwargs=None)[source]

Saves a 2d profile plot.

Parameters:
  • name (str, optional) – The output file keyword.

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

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

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_cmap(field, cmap)

set the colormap for one of the fields

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

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

set_colorbar_label(field, label)

Sets the colorbar label.

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

  • label (str) – The new label

  • plot.set_colorbar_label( (>>>) –

  • ("gas" (...) –

  • "density")

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

  • ) (...) –

set_colorbar_minorticks(field, state)

turn colorbar minor ticks on or off in the current plot

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

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

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

set_figure_size(size)

Sets a new figure size for the plot

Parameters:

size (float, 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)[source]

set a field to log or linear.

Parameters:
  • field (string) – the field to set a transform

  • log (boolean) – Log on/off.

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_title(field, title)[source]

Set a title for the plot.

Parameters:
  • field (str) – The z field of the plot to add the title.

  • title (str) – The title to add.

Examples

>>> plot.set_title(("gas", "mass"), "This is a phase plot")
set_transform(field, name: str)
set_unit(field, unit)[source]

Sets a new unit for the requested field

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

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

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_xlim(xmin=None, xmax=None)[source]

Sets the limits of the x bin field

Parameters:
  • xmin (float or None) – The new x minimum in the current x-axis units. Defaults to None, which leaves the xmin unchanged.

  • xmax (float or None) – The new x maximum in the current x-axis units. Defaults to None, which leaves the xmax unchanged.

Examples

>>> import yt
>>> ds = yt.load("IsolatedGalaxy/galaxy0030/galaxy0030")
>>> pp = yt.PhasePlot(ds.all_data(), "density", "temperature", ("gas", "mass"))
>>> pp.set_xlim(1e-29, 1e-24)
>>> pp.save()
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_ylim(ymin=None, ymax=None)[source]

Sets the plot limits for the y bin field.

Parameters:
  • ymin (float or None) – The new y minimum in the current y-axis units. Defaults to None, which leaves the ymin unchanged.

  • ymax (float or None) – The new y maximum in the current y-axis units. Defaults to None, which leaves the ymax unchanged.

Examples

>>> import yt
>>> ds = yt.load("IsolatedGalaxy/galaxy0030/galaxy0030")
>>> pp = yt.PhasePlot(
...     ds.all_data(),
...     ("gas", "density"),
...     ("gas", "temperature"),
...     ("gas", "mass"),
... )
>>> pp.set_ylim(1e4, 1e6)
>>> pp.save()
set_zlim(field, zmin: float | ~unyt.array.unyt_quantity | tuple[float, ~unyt.unit_object.Unit | str] | ~typing.Literal['min'] | ~yt.visualization.plot_container.Unset = <yt.visualization.plot_container.Unset object>, zmax: float | ~unyt.array.unyt_quantity | tuple[float, ~unyt.unit_object.Unit | str] | ~typing.Literal['max'] | ~yt.visualization.plot_container.Unset = <yt.visualization.plot_container.Unset object>, dynamic_range: float | None = 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, 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) –

x_log = None
y_log = None
class yt.visualization.profile_plotter.PhasePlotMPL(x_data, y_data, data, x_scale, y_scale, figure_size, fontsize, figure, axes, cax, shading='nearest', *, norm_handler: NormHandler, colorbar_handler: ColorbarHandler)[source]

Bases: ImagePlotMPL

A container for a single matplotlib figure and axes for a PhasePlot

hide_axes(*, draw_frame=None)

Hide the axes for a plot including ticks and labels

hide_colorbar()

Hide the colorbar for a plot including ticks and labels

save(name, mpl_kwargs=None, canvas=None)

Choose backend and save image to disk

show()
show_axes()

Show the axes for a plot including ticks and labels

show_colorbar()

Show the colorbar for a plot including ticks and labels

class yt.visualization.profile_plotter.ProfilePlot(data_source, x_field, y_fields, weight_field=('gas', 'mass'), n_bins=64, accumulation=False, fractional=False, label=None, plot_spec=None, x_log=True, y_log=True)[source]

Bases: BaseLinePlot

Create a 1d profile plot from a data source or from a list of profile objects.

Given a data object (all_data, region, sphere, etc.), an x field, and a y field (or fields), this will create a one-dimensional profile of the average (or total) value of the y field in bins of the x field.

This can be used to create profiles from given fields or to plot multiple profiles created from yt.data_objects.profiles.create_profile.

Parameters:
  • data_source (YTSelectionContainer Object) – The data object to be profiled, such as all_data, region, or sphere. If a dataset is passed in instead, an all_data data object is generated internally from the dataset.

  • x_field (str) – The binning field for the profile.

  • y_fields (str or list) – The field or fields to be profiled.

  • weight_field (str) – The weight field for calculating weighted averages. If None, the profile values are the sum of the field values within the bin. Otherwise, the values are a weighted average. Default : (“gas”, “mass”)

  • n_bins (int) – The number of bins in the profile. Default: 64.

  • accumulation (bool) – If True, the profile values for a bin N are the cumulative sum of all the values from bin 0 to N. Default: False.

  • fractional (If True the profile values are divided by the sum of all) – the profile data such that the profile represents a probability distribution function.

  • label (str or list of strings) – If a string, the label to be put on the line plotted. If a list, this should be a list of labels for each profile to be overplotted. Default: None.

  • plot_spec (dict or list of dicts) – A dictionary or list of dictionaries containing plot keyword arguments. For example, dict(color=”red”, linestyle=”:”). Default: None.

  • x_log (bool) – Whether the x_axis should be plotted with a logarithmic scaling (True), or linear scaling (False). Default: True.

  • y_log (dict or bool) – A dictionary containing field:boolean pairs, setting the logarithmic property for that field. May be overridden after instantiation using set_log A single boolean can be passed to signify all fields should use logarithmic (True) or linear scaling (False). Default: True.

Examples

This creates profiles of a single dataset.

>>> import yt
>>> ds = yt.load("enzo_tiny_cosmology/DD0046/DD0046")
>>> ad = ds.all_data()
>>> plot = yt.ProfilePlot(
...     ad,
...     ("gas", "density"),
...     [("gas", "temperature"), ("gas", "velocity_x")],
...     weight_field=("gas", "mass"),
...     plot_spec=dict(color="red", linestyle="--"),
... )
>>> plot.save()

This creates profiles from a time series object.

>>> es = yt.load_simulation("AMRCosmology.enzo", "Enzo")
>>> es.get_time_series()
>>> profiles = []
>>> labels = []
>>> plot_specs = []
>>> for ds in es[-4:]:
...     ad = ds.all_data()
...     profiles.append(
...         create_profile(
...             ad,
...             [("gas", "density")],
...             fields=[("gas", "temperature"), ("gas", "velocity_x")],
...         )
...     )
...     labels.append(ds.current_redshift)
...     plot_specs.append(dict(linestyle="--", alpha=0.7))
>>> plot = yt.ProfilePlot.from_profiles(
...     profiles, labels=labels, plot_specs=plot_specs
... )
>>> plot.save()

Use set_line_property to change line properties of one or all profiles.

annotate_text(xpos=0.0, ypos=0.0, text=None, field='all', **text_kwargs)[source]

Allow the user to insert text onto the plot

The x-position and y-position must be given as well as the text string. Add text to plot at location xpos, ypos in plot coordinates for the given fields or by default for all fields. (see example below).

Parameters:
  • xpos (float) – Position on plot in x-coordinates.

  • ypos (float) – Position on plot in y-coordinates.

  • text (str) – The text to insert onto the plot.

  • field (>>> # Annotate text for a given) – The name of the field to add text to.

  • **text_kwargs (dict) – Extra keyword arguments will be passed to matplotlib text instance

  • yt (>>> import) –

  • kpc (10 *) –

  • yt.load("IsolatedGalaxy/galaxy0030/galaxy0030") (>>> ds =) –

  • ds.disk(ds.domain_center (>>> my_galaxy =) –

  • [0.0

  • 0.0

  • 1.0]

  • kpc

  • kpc) (3 *) –

  • yt.ProfilePlot( (>>> plot =) –

  • my_galaxy (...) –

  • ("gas"

  • "density")

  • [("gas" (>>> fields =) –

  • "temperature")]

  • ) (...) –

  • fields (>>> # Annotate text for multiple) –

  • plot.annotate_text(1e-26 (>>>) –

  • 1e5

  • area.") ("This is annotated text in the plot) –

  • plot.save() (>>>) –

  • field

  • plot.annotate_text(1e-26

  • 1e5

  • text" ("Annotated) –

  • ("gas"

  • "temperature"))

  • plot.save()

  • fields

  • [("gas"

  • "temperature")

  • ("gas"

  • "density")]

  • plot.annotate_text(1e-26

  • 1e5

  • text"

  • fields)

  • plot.save()

annotate_title(title, field='all')[source]

Set a title for the plot.

Parameters:
  • title (str) – The title to add.

  • field (str or list of str) – The field name for which title needs to be set.

Examples

>>> # To set title for all the fields:
>>> plot.annotate_title("This is a Profile Plot")
>>> # To set title for specific fields:
>>> plot.annotate_title("Profile Plot for Temperature", ("gas", "temperature"))
>>> # Setting same plot title for both the given fields
>>> plot.annotate_title(
...     "Profile Plot: Temperature-Dark Matter Density",
...     [("gas", "temperature"), ("deposit", "dark_matter_density")],
... )
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.

classmethod from_profiles(profiles, labels=None, plot_specs=None, y_log=None)[source]

Instantiate a ProfilePlot object from a list of profiles created with create_profile().

Parameters:
  • profiles (a profile or list of profiles) – A single profile or list of profile objects created with create_profile().

  • labels (list of strings) – A list of labels for each profile to be overplotted. Default: None.

  • plot_specs (list of dicts) – A list of dictionaries containing plot keyword arguments. For example, [dict(color=”red”, linestyle=”:”)]. Default: None.

Examples

>>> from yt import load_simulation
>>> es = load_simulation("AMRCosmology.enzo", "Enzo")
>>> es.get_time_series()
>>> profiles = []
>>> labels = []
>>> plot_specs = []
>>> for ds in es[-4:]:
...     ad = ds.all_data()
...     profiles.append(
...         create_profile(
...             ad,
...             [("gas", "density")],
...             fields=[("gas", "temperature"), ("gas", "velocity_x")],
...         )
...     )
...     labels.append(ds.current_redshift)
...     plot_specs.append(dict(linestyle="--", alpha=0.7))
>>> plot = ProfilePlot.from_profiles(
...     profiles, labels=labels, plot_specs=plot_specs
... )
>>> plot.save()
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 | None = None, suffix: str | None = None, mpl_kwargs: dict[str, Any] | None = None)[source]

Saves a 1d profile plot.

Parameters:
  • name (str, optional) – The output file keyword.

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

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_line_property(property, value, index=None)[source]

Set properties for one or all lines to be plotted.

Parameters:
  • property (str) – The line property to be set.

  • value (str, int, float) – The value to set for the line property.

  • index (int) – The index of the profile in the list of profiles to be changed. If None, change all plotted lines. Default : None.

Examples

Change all the lines in a plot plot.set_line_property(“linestyle”, “-“)

Change a single line. plot.set_line_property(“linewidth”, 4, index=0)

set_log(field, log)[source]

set a field to log or linear.

Parameters:
  • field (string) – the field to set a transform

  • log (boolean) – Log on/off.

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_unit(field, unit)[source]

Sets a new unit for the requested field

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

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

set_xlabel(label)[source]

Sets a new xlabel for all profiles

Parameters:

label (string) – The label to be placed on the x-axis

set_xlim(xmin=None, xmax=None)[source]

Sets the limits of the bin field

Parameters:
  • xmin (float or None) – The new x minimum. Defaults to None, which leaves the xmin unchanged.

  • xmax (float or None) – The new x maximum. Defaults to None, which leaves the xmax unchanged.

Examples

>>> import yt
>>> ds = yt.load("IsolatedGalaxy/galaxy0030/galaxy0030")
>>> pp = yt.ProfilePlot(
...     ds.all_data(), ("gas", "density"), ("gas", "temperature")
... )
>>> pp.set_xlim(1e-29, 1e-24)
>>> pp.save()
set_ylabel(field, label)[source]

Sets a new ylabel for the specified fields

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

  • label (string) – The label to be placed on the y-axis

set_ylim(field, ymin=None, ymax=None)[source]

Sets the plot limits for the specified field we are binning.

Parameters:
  • field (string or field tuple) –

  • for. (The field that we want to adjust the plot limits) –

  • ymin (float or None) – The new y minimum. Defaults to None, which leaves the ymin unchanged.

  • ymax (float or None) – The new y maximum. Defaults to None, which leaves the ymax unchanged.

Examples

>>> import yt
>>> ds = yt.load("IsolatedGalaxy/galaxy0030/galaxy0030")
>>> pp = yt.ProfilePlot(
...     ds.all_data(),
...     ("gas", "density"),
...     [("gas", "temperature"), ("gas", "velocity_x")],
... )
>>> pp.set_ylim(("gas", "temperature"), 1e4, 1e6)
>>> pp.save()
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

>>> import yt
>>> ds = yt.load("IsolatedGalaxy/galaxy0030/galaxy0030")
>>> pp = ProfilePlot(ds.all_data(), ("gas", "density"), ("gas", "temperature"))
>>> pp.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) –

x_log = None
x_title = None
y_log = None
y_title = None
yt.visualization.profile_plotter.data_object_or_all_data(data_source)[source]
yt.visualization.profile_plotter.invalidate_profile(f)[source]
yt.visualization.profile_plotter.sanitize_label(labels, nprofiles)[source]