# yt.visualization.line_plot module¶

class yt.visualization.line_plot.LineBuffer(ds, start_point, end_point, npoints, label=None)[source]

Bases: object

This takes a data source and implements a protocol for generating a ‘pixelized’, fixed-resolution line buffer. In other words, LineBuffer takes a starting point, ending point, and number of sampling points and can subsequently generate YTArrays of field values along the sample points.

Parameters
• ds (yt.data_objects.static_output.Dataset) – This is the dataset object holding the data that can be sampled by the LineBuffer

• start_point (n-element list, tuple, ndarray, or YTArray) – Contains the coordinates of the first point for constructing the LineBuffer. Must contain n elements where n is the dimensionality of the dataset.

• end_point (n-element list, tuple, ndarray, or YTArray) – Contains the coordinates of the first point for constructing the LineBuffer. Must contain n elements where n is the dimensionality of the dataset.

• npoints (int) – How many points to sample between start_point and end_point

Examples

>>> lb = yt.LineBuffer(ds, (0.25, 0, 0), (0.25, 1, 0), 100)
>>> lb[("all", "u")].max()
0.11562424257143075 dimensionless

keys()[source]
class yt.visualization.line_plot.LinePlot(ds, fields, start_point, end_point, npoints, figure_size=5, fontsize=14, field_labels=None)[source]

A class for constructing line plots

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

• fields (string / tuple, or list of strings / tuples) – The name(s) of the field(s) to be plotted.

• start_point (n-element list, tuple, ndarray, or YTArray) – Contains the coordinates of the first point for constructing the line. Must contain n elements where n is the dimensionality of the dataset.

• end_point (n-element list, tuple, ndarray, or YTArray) – Contains the coordinates of the first point for constructing the line. Must contain n elements where n is the dimensionality of the dataset.

• npoints (int) – How many points to sample between start_point and end_point for constructing the line plot

• figure_size (int or two-element iterable of ints) – Size in inches of the image. Default: 5 (5x5)

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

• field_labels (dictionary) – Keys should be the field names. Values should be latex-formattable strings used in the LinePlot legend Default: None

Example

>>> import yt

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

>>> plot = yt.LinePlot(ds, "density", [0, 0, 0], [1, 1, 1], 512)
>>> plot.set_x_unit("cm")
>>> plot.set_unit("density", "kg/cm**3")
>>> plot.save()

annotate_legend(field)[source]

Adds a legend to the LinePlot instance. The _sanitize_dimensions call ensures that a legend label will be added for every field of a multi-field plot

annotate_title(field, title)[source]

Set the unit used to plot the field

Parameters
• field (str or field tuple) – The name of the field to set the units for

• title (str) – The title to use for the 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.

classmethod from_lines(ds, fields, lines, figure_size=5, font_size=14, field_labels=None)[source]

A class method for constructing a line plot from multiple sampling lines

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

• fields (field name or list of field names) – The name(s) of the field(s) to be plotted.

• lines (list of yt.visualization.line_plot.LineBuffer instances) – The lines from which to sample data

• figure_size (int or two-element iterable of ints) – Size in inches of the image. Default: 5 (5x5)

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

• field_labels (dictionary) – Keys should be the field names. Values should be latex-formattable strings used in the LinePlot legend Default: None

Example

>>> ds = yt.load(
...     "SecondOrderTris/RZ_p_no_parts_do_nothing_bcs_cone_out.e", step=-1
... )
>>> fields = [field for field in ds.field_list if field[0] == "all"]
>>> lines = [
...     yt.LineBuffer(ds, [0.25, 0, 0], [0.25, 1, 0], 100, label="x = 0.25"),
...     yt.LineBuffer(ds, [0.5, 0, 0], [0.5, 1, 0], 100, label="x = 0.5"),
... ]
>>> lines.append()

>>> plot = yt.LinePlot.from_lines(ds, fields, lines)
>>> 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=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_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_unit(field, unit_name)[source]

Set the unit used to plot the field

Parameters
• field (str or field tuple) – The name of the field to set the units for

• unit_name (str) – The name of the unit to use for this field

set_x_unit(unit_name)[source]

Set the unit to use along the x-axis

Parameters

unit_name (str) – The name of the unit to use for the x-axis 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.

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

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.line_plot.LinePlotDictionary(data_source)[source]
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