yt.visualization.plot_modifications module

class yt.visualization.plot_modifications.ArrowCallback(pos, *, length=0.03, width=0.0001, head_width=0.01, head_length=0.01, starting_pos=None, coord_system='data', plot_args: dict[str, Any] | None = None, **kwargs)[source]

Bases: PlotCallback

Overplot arrow(s) pointing at position(s) for highlighting specific features. By default, arrow points from lower left to the designated position “pos” with arrow length “length”. Alternatively, if “starting_pos” is set, arrow will stretch from “starting_pos” to “pos” and “length” will be disregarded.

“coord_system” keyword refers to positions set in “pos” arg and “starting_pos” keyword, which by default are in data coordinates.

“length”, “width”, “head_length”, and “head_width” keywords for the arrow are all in axis units, ie relative to the size of the plot axes as 1, even if the position of the arrow is set relative to another coordinate system.

Parameters:
  • pos (array-like) – These are the coordinates where the marker(s) will be overplotted Either as [x,y,z] or as [[x1,x2,…],[y1,y2,…],[z1,z2,…]]

  • length (float, optional) – The length, in axis units, of the arrow. Default: 0.03

  • width (float, optional) – The width, in axis units, of the tail line of the arrow. Default: 0.003

  • head_length (float, optional) – The length, in axis units, of the head of the arrow. If set to None, use 1.5*head_width Default: None

  • head_width (float, optional) – The width, in axis units, of the head of the arrow. Default: 0.02

  • starting_pos (2- or 3-element tuple, list, or array, optional) – These are the coordinates from which the arrow starts towards its point. Not compatible with ‘length’ kwarg.

  • coord_system (string, optional) –

    This string defines the coordinate system of the coordinates of pos Valid coordinates are:

    ”data” – the 3D dataset coordinates

    ”plot” – the 2D coordinates defined by the actual plot limits

    ”axis” – the MPL axis coordinates: (0,0) is lower left; (1,1) is

    upper right

    ”figure” – the MPL figure coordinates: (0,0) is lower left, (1,1)

    is upper right

  • plot_args (dictionary, optional) – This dictionary is passed to the MPL arrow function for generating the arrow. By default, it is: {‘color’:’white’}

Examples

>>> # Overplot an arrow pointing to feature at data coord: (0.2, 0.3, 0.4)
>>> import yt
>>> ds = yt.load("IsolatedGalaxy/galaxy0030/galaxy0030")
>>> s = yt.SlicePlot(ds, "z", "density")
>>> s.annotate_arrow([0.2, 0.3, 0.4])
>>> s.save()
>>> # Overplot a red arrow with longer length pointing to plot coordinate
>>> # (0.1, -0.1)
>>> import yt
>>> ds = yt.load("IsolatedGalaxy/galaxy0030/galaxy0030")
>>> s = yt.SlicePlot(ds, "z", "density")
>>> s.annotate_arrow(
...     [0.1, -0.1], length=0.06, coord_system="plot", color="red"
... )
>>> s.save()
class yt.visualization.plot_modifications.BaseQuiverCallback(field_x, field_y, field_c=None, *, factor: tuple[int, int] | int = 16, scale=None, scale_units=None, normalize=False, plot_args=None, **kwargs)[source]

Bases: PlotCallback, ABC

class yt.visualization.plot_modifications.CellEdgesCallback(line_width=0.002, alpha=1.0, color='black')[source]

Bases: PlotCallback

Annotate cell edges. This is done through a second call to pixelize, where the distance from a pixel to a cell boundary in pixels is compared against the line_width argument. The secondary image is colored as color and overlaid with the alpha value.

Parameters:
  • line_width (float) – The width of the cell edge lines in normalized units relative to the size of the longest axis. Default is 1% of the size of the smallest axis.

  • alpha (float) – When the second image is overlaid, it will have this level of alpha transparency. Default is 1.0 (fully-opaque).

  • color (tuple of three floats or matplotlib color name) – This is the color of the cell edge values. It defaults to black.

Examples

>>> import yt
>>> ds = yt.load("IsolatedGalaxy/galaxy0030/galaxy0030")
>>> s = yt.SlicePlot(ds, "z", "density")
>>> s.annotate_cell_edges()
>>> s.save()
class yt.visualization.plot_modifications.ClumpContourCallback(clumps, *, plot_args=None, **kwargs)[source]

Bases: PlotCallback

Take a list of clumps and plot them as a set of contours.

class yt.visualization.plot_modifications.ContourCallback(field: tuple[str, str] | str, levels: int = 5, *, factor: tuple[int, int] | int = 4, clim: tuple[float, float] | None = None, label: bool = False, take_log: bool | None = None, data_source: YTDataContainer | None = None, plot_args: dict[str, Any] | None = None, text_args: dict[str, Any] | None = None, ncont: int | None = None)[source]

Bases: PlotCallback

Add contours in field to the plot. levels governs the number of contours generated, factor governs the number of points used in the interpolation, take_log governs how it is contoured and clim gives the (upper, lower) limits for contouring. An alternate data source can be specified with data_source, but by default the plot’s data source will be queried.

class yt.visualization.plot_modifications.CuttingQuiverCallback(field_x, field_y, field_c=None, *, factor: tuple[int, int] | int = 16, scale=None, scale_units=None, normalize=False, plot_args=None, **kwargs)[source]

Bases: BaseQuiverCallback

Get a quiver plot on top of a cutting plane, using field_x and field_y, skipping every factor datapoint in the discretization. scale is the data units per arrow length unit using scale_units and plot_args allows you to pass in matplotlib arguments (see matplotlib.axes.Axes.quiver for more info). if normalize is True, the fields will be scaled by their local (in-plane) length, allowing morphological features to be more clearly seen for fields with substantial variation in field strength.

class yt.visualization.plot_modifications.GridBoundaryCallback(alpha=0.7, min_pix=1, min_pix_ids=20, draw_ids=False, id_loc=None, periodic=True, min_level=None, max_level=None, cmap='B-W LINEAR_r', edgecolors=None, linewidth=1.0)[source]

Bases: PlotCallback

Draws grids on an existing PlotWindow object. Adds grid boundaries to a plot, optionally with alpha-blending. By default, colors different levels of grids with different colors going from white to black, but you can change to any arbitrary colormap with cmap keyword, to all black grid edges for all levels with cmap=None and edgecolors=None, or to an arbitrary single color for grid edges with edgecolors=’YourChosenColor’ defined in any of the standard ways (e.g., edgecolors=’white’, edgecolors=’r’, edgecolors=’#00FFFF’, or edgecolor=’0.3’, where the last is a float in 0-1 scale indicating gray). Note that setting edgecolors overrides cmap if you have both set to non-None values. Cutoff for display is at min_pix wide. draw_ids puts the grid id a the corner of the grid (but its not so great in projections…). id_loc determines which corner holds the grid id. One can set min and maximum level of grids to display, and can change the linewidth of the displayed grids.

class yt.visualization.plot_modifications.LineIntegralConvolutionCallback(field_x, field_y, texture=None, kernellen=50.0, lim=(0.5, 0.6), cmap='binary', alpha=0.8, const_alpha=False)[source]

Bases: PlotCallback

Add the line integral convolution to the plot for vector fields visualization. Two component of vector fields needed to be provided (i.e., velocity_x and velocity_y, magnetic_field_x and magnetic_field_y).

Parameters:
  • field_x (string) – The names of two components of vector field which will be visualized

  • field_y (string) – The names of two components of vector field which will be visualized

  • texture (2-d array with the same shape of image, optional) – Texture will be convolved when computing line integral convolution. A white noise background will be used as default.

  • kernellen (float, optional) – The lens of kernel for convolution, which is the length over which the convolution will be performed. For longer kernellen, longer streamline structure will appear.

  • lim (2-element tuple, list, or array, optional) – The value of line integral convolution will be clipped to the range of lim, which applies upper and lower bounds to the values of line integral convolution and enhance the visibility of plots. Each element should be in the range of [0,1].

  • cmap (string, optional) – The name of colormap for line integral convolution plot.

  • alpha (float, optional) – The alpha value for line integral convolution plot.

  • const_alpha (boolean, optional) – If set to False (by default), alpha will be weighted spatially by the values of line integral convolution; otherwise a constant value of the given alpha is used.

Example

>>> import yt
>>> ds = yt.load("Enzo_64/DD0020/data0020")
>>> s = yt.SlicePlot(ds, "z", "density")
>>> s.annotate_line_integral_convolution(
...     "velocity_x", "velocity_y", lim=(0.5, 0.65)
... )
class yt.visualization.plot_modifications.LinePlotCallback(p1, p2, *, coord_system='data', plot_args: dict[str, Any] | None = None, **kwargs)[source]

Bases: PlotCallback

Overplot a line with endpoints at p1 and p2. p1 and p2 should be 2D or 3D coordinates consistent with the coordinate system denoted in the “coord_system” keyword.

Parameters:
  • p1 (2- or 3-element tuples, lists, or arrays) – These are the coordinates of the endpoints of the line.

  • p2 (2- or 3-element tuples, lists, or arrays) – These are the coordinates of the endpoints of the line.

  • coord_system (string, optional) –

    This string defines the coordinate system of the coordinates p1 and p2. Valid coordinates are:

    ”data” – the 3D dataset coordinates

    ”plot” – the 2D coordinates defined by the actual plot limits

    ”axis” – the MPL axis coordinates: (0,0) is lower left; (1,1) is

    upper right

    ”figure” – the MPL figure coordinates: (0,0) is lower left, (1,1)

    is upper right

  • plot_args (dictionary, optional) – This dictionary is passed to the MPL plot function for generating the line. By default, it is: {‘color’:’white’, ‘linewidth’:2}

Examples

>>> # Overplot a diagonal white line from the lower left corner to upper
>>> # right corner
>>> import yt
>>> ds = yt.load("IsolatedGalaxy/galaxy0030/galaxy0030")
>>> s = yt.SlicePlot(ds, "z", "density")
>>> s.annotate_line([0, 0], [1, 1], coord_system="axis")
>>> s.save()
>>> # Overplot a red dashed line from data coordinate (0.1, 0.2, 0.3) to
>>> # (0.5, 0.6, 0.7)
>>> import yt
>>> ds = yt.load("IsolatedGalaxy/galaxy0030/galaxy0030")
>>> s = yt.SlicePlot(ds, "z", "density")
>>> s.annotate_line(
...     [0.1, 0.2, 0.3],
...     [0.5, 0.6, 0.7],
...     coord_system="data",
...     color="red",
...     linestyles="--",
... )
>>> s.save()
class yt.visualization.plot_modifications.MagFieldCallback(factor: tuple[int, int] | int = 16, *, scale=None, scale_units=None, normalize=False, plot_args=None, **kwargs)[source]

Bases: PlotCallback

Adds a ‘quiver’ plot of magnetic field to the plot, skipping all but every factor datapoint. scale is the data units per arrow length unit using scale_units and plot_args allows you to pass in matplotlib arguments (see matplotlib.axes.Axes.quiver for more info). if normalize is True, the magnetic fields will be scaled by their local (in-plane) length, allowing morphological features to be more clearly seen for fields with substantial variation in field strength.

class yt.visualization.plot_modifications.MarkerAnnotateCallback(pos, marker='x', *, coord_system='data', plot_args=None, **kwargs)[source]

Bases: PlotCallback

Overplot marker(s) at a position(s) for highlighting specific features.

Parameters:
  • pos (array-like) – These are the coordinates where the marker(s) will be overplotted Either as [x,y,z] or as [[x1,x2,…],[y1,y2,…],[z1,z2,…]]

  • marker (string, optional) – The shape of the marker to be passed to the MPL scatter function. By default, it is ‘x’, but other acceptable values are: ‘.’, ‘o’, ‘v’, ‘^’, ‘s’, ‘p’ ‘*’, etc. See matplotlib.markers for more information.

  • coord_system (string, optional) –

    This string defines the coordinate system of the coordinates of pos Valid coordinates are:

    ”data” – the 3D dataset coordinates

    ”plot” – the 2D coordinates defined by the actual plot limits

    ”axis” – the MPL axis coordinates: (0,0) is lower left; (1,1) is

    upper right

    ”figure” – the MPL figure coordinates: (0,0) is lower left, (1,1)

    is upper right

  • plot_args (dictionary, optional) – This dictionary is passed to the MPL scatter function for generating the marker. By default, it is: {‘color’:’white’, ‘s’:50}

Examples

>>> # Overplot a white X on a feature at data location (0.5, 0.5, 0.5)
>>> import yt
>>> ds = yt.load("IsolatedGalaxy/galaxy0030/galaxy0030")
>>> s = yt.SlicePlot(ds, "z", "density")
>>> s.annotate_marker([0.4, 0.5, 0.6])
>>> s.save()
>>> # Overplot a big yellow circle at axis location (0.1, 0.2)
>>> import yt
>>> ds = yt.load("IsolatedGalaxy/galaxy0030/galaxy0030")
>>> s = yt.SlicePlot(ds, "z", "density")
>>> s.annotate_marker(
...     [0.1, 0.2],
...     marker="o",
...     coord_system="axis",
...     color="yellow",
...     s=200,
... )
>>> s.save()
class yt.visualization.plot_modifications.MeshLinesCallback(*, plot_args=None, **kwargs)[source]

Bases: PlotCallback

Adds mesh lines to the plot. Only works for unstructured or semi-structured mesh data. For structured grid data, see GridBoundaryCallback or CellEdgesCallback.

Parameters:

plot_args (dict, optional) – A dictionary of arguments that will be passed to matplotlib.

Example

>>> import yt
>>> ds = yt.load("MOOSE_sample_data/out.e-s010")
>>> sl = yt.SlicePlot(ds, "z", ("connect2", "convected"))
>>> sl.annotate_mesh_lines(color="black")
promote_2d_to_3d(coords, indices, plot)[source]
class yt.visualization.plot_modifications.ParticleCallback(width, p_size=1.0, col='k', marker='o', stride=1, ptype='all', alpha=1.0, data_source=None)[source]

Bases: PlotCallback

Adds particle positions, based on a thick slab along axis with a width along the line of sight. p_size controls the number of pixels per particle, and col governs the color. ptype will restrict plotted particles to only those that are of a given type. alpha determines the opacity of the marker symbol used in the scatter. An alternate data source can be specified with data_source, but by default the plot’s data source will be queried.

region = None
class yt.visualization.plot_modifications.PlotCallback(*args, **kwargs)[source]

Bases: ABC

class yt.visualization.plot_modifications.QuiverCallback(field_x, field_y, field_c=None, *, factor: tuple[int, int] | int = 16, scale=None, scale_units=None, normalize=False, bv_x=0, bv_y=0, plot_args=None, **kwargs)[source]

Bases: BaseQuiverCallback

Adds a ‘quiver’ plot to any plot, using the field_x and field_y from the associated data, skipping every factor pixels. field_c is an optional field name used for color. scale is the data units per arrow length unit using scale_units and plot_args allows you to pass in matplotlib arguments (see matplotlib.axes.Axes.quiver for more info). if normalize is True, the fields will be scaled by their local (in-plane) length, allowing morphological features to be more clearly seen for fields with substantial variation in field strength.

class yt.visualization.plot_modifications.RayCallback(ray, *, arrow=False, plot_args=None, **kwargs)[source]

Bases: PlotCallback

Adds a line representing the projected path of a ray across the plot. The ray can be either a YTOrthoRay, YTRay, or a LightRay object. annotate_ray() will properly account for periodic rays across the volume. If arrow is set to True, uses the MPL.pyplot.arrow function, otherwise uses the MPL.pyplot.plot function to plot a normal line. Adjust plot_args accordingly.

Parameters:
  • ray (YTOrthoRay, YTRay, or LightRay) – Ray is the object that we want to include. We overplot the projected trajectory of the ray. If the object is a trident.LightRay object, it will only plot the segment of the LightRay that intersects the dataset currently displayed.

  • arrow (boolean, optional) – Whether or not to place an arrowhead on the front of the ray to denote direction Default: False

  • plot_args (dictionary, optional) – A dictionary of any arbitrary parameters to be passed to the Matplotlib line object. Defaults: {‘color’:’white’, ‘linewidth’:2}.

Examples

>>> # Overplot a ray and an ortho_ray object on a projection
>>> import yt
>>> ds = yt.load("IsolatedGalaxy/galaxy0030/galaxy0030")
>>> oray = ds.ortho_ray(1, (0.3, 0.4))  # orthoray down the y axis
>>> ray = ds.ray((0.1, 0.2, 0.3), (0.6, 0.7, 0.8))  # arbitrary ray
>>> p = yt.ProjectionPlot(ds, "z", "density")
>>> p.annotate_ray(oray)
>>> p.annotate_ray(ray)
>>> p.save()
>>> # Overplot a LightRay object on a projection
>>> import yt
>>> from trident import LightRay
>>> ds = yt.load("enzo_cosmology_plus/RD0004/RD0004")
>>> lr = LightRay(
...     "enzo_cosmology_plus/AMRCosmology.enzo", "Enzo", 0.0, 0.1, time_data=False
... )
>>> lray = lr.make_light_ray(seed=1)
>>> p = yt.ProjectionPlot(ds, "z", "density")
>>> p.annotate_ray(lr)
>>> p.save()
class yt.visualization.plot_modifications.ScaleCallback(*, corner='lower_right', coeff=None, unit=None, pos=None, max_frac=0.16, min_frac=0.015, coord_system='axis', text_args=None, size_bar_args=None, draw_inset_box=False, inset_box_args=None, scale_text_format='{scale} {units}')[source]

Bases: PlotCallback

Annotates the scale of the plot at a specified location in the image (either in a preset corner, or by specifying (x,y) image coordinates with the pos argument. Coeff and units (e.g. 1 Mpc or 100 kpc) refer to the distance scale you desire to show on the plot. If no coeff and units are specified, an appropriate pair will be determined such that your scale bar is never smaller than min_frac or greater than max_frac of your plottable axis length. Additional customization of the scale bar is possible by adjusting the text_args and size_bar_args dictionaries. The text_args dictionary accepts matplotlib’s font_properties arguments to override the default font_properties for the current plot. The size_bar_args dictionary accepts keyword arguments for the AnchoredSizeBar class in matplotlib’s axes_grid toolkit.

Parameters:
  • corner (string, optional) – Corner sets up one of 4 predeterimined locations for the scale bar to be displayed in the image: ‘upper_left’, ‘upper_right’, ‘lower_left’, ‘lower_right’ (also allows None). This value will be overridden by the optional ‘pos’ keyword.

  • coeff (float, optional) – The coefficient of the unit defining the distance scale (e.g. 10 kpc or 100 Mpc) for overplotting. If set to None along with unit keyword, coeff will be automatically determined to be a power of 10 relative to the best-fit unit.

  • unit (string, optional) – unit must be a valid yt distance unit (e.g. ‘m’, ‘km’, ‘AU’, ‘pc’, ‘kpc’, etc.) or set to None. If set to None, will be automatically determined to be the best-fit to the data.

  • pos (2- or 3-element tuples, lists, or arrays, optional) – The image location of the scale bar in the plot coordinate system. Setting pos overrides the corner parameter.

  • min_frac (float, optional) – The minimum/maximum fraction of the axis width for the scale bar to extend. A value of 1 would allow the scale bar to extend across the entire axis width. Only used for automatically calculating best-fit coeff and unit when neither is specified, otherwise disregarded.

  • max_frac (float, optional) – The minimum/maximum fraction of the axis width for the scale bar to extend. A value of 1 would allow the scale bar to extend across the entire axis width. Only used for automatically calculating best-fit coeff and unit when neither is specified, otherwise disregarded.

  • coord_system (string, optional) –

    This string defines the coordinate system of the coordinates of pos Valid coordinates are:

    • ”data”: 3D dataset coordinates

    • ”plot”: 2D coordinates defined by the actual plot limits

    • ”axis”: MPL axis coordinates: (0,0) is lower left; (1,1) is upper right

    • ”figure”: MPL figure coordinates: (0,0) is lower left, (1,1) is upper right

  • text_args (dictionary, optional) – A dictionary of parameters to used to update the font_properties for the text in this callback. For any property not set, it will use the defaults of the plot. Thus one can modify the text size with text_args={'size':24}

  • size_bar_args (dictionary, optional) – A dictionary of parameters to be passed to the Matplotlib AnchoredSizeBar initializer. Defaults: {'pad': 0.25, 'sep': 5, 'borderpad': 1, 'color': 'w'}

  • draw_inset_box (boolean, optional) – Whether or not an inset box should be included around the scale bar.

  • inset_box_args (dictionary, optional) – A dictionary of keyword arguments to be passed to the matplotlib Patch object that represents the inset box. Defaults: {'facecolor': 'black', 'linewidth': 3, 'edgecolor': 'white', 'alpha': 0.5, 'boxstyle': 'square'}

  • scale_text_format (string, optional) – This specifies the format of the scalebar value assuming “scale” is the numerical value and “unit” is units of the scale (e.g. ‘cm’, ‘kpc’, etc.) The scale can be specified to arbitrary precision according to printf formatting codes. The format string must only specify “scale” and “units”. Example: “Length = {scale:.2f} {units}”. Default: “{scale} {units}”

Example

>>> import yt
>>> ds = yt.load("Enzo_64/DD0020/data0020")
>>> s = yt.SlicePlot(ds, "z", "density")
>>> s.annotate_scale()
class yt.visualization.plot_modifications.SphereCallback(center, radius, *, coord_system='data', text=None, circle_args=None, text_args=None)[source]

Bases: PlotCallback

Overplot a circle with designated center and radius with optional text.

Parameters:
  • center (2- or 3-element tuple, list, or array) – These are the coordinates where the circle will be overplotted

  • radius (YTArray, float, or (1, ('kpc')) style tuple) – The radius of the circle in code coordinates

  • circle_args (dict, optional) – This dictionary is passed to the MPL circle object. By default, {‘color’:’white’}

  • coord_system (string, optional) –

    This string defines the coordinate system of the coordinates of pos Valid coordinates are:

    ”data” – the 3D dataset coordinates

    ”plot” – the 2D coordinates defined by the actual plot limits

    ”axis” – the MPL axis coordinates: (0,0) is lower left; (1,1) is

    upper right

    ”figure” – the MPL figure coordinates: (0,0) is lower left, (1,1)

    is upper right

  • text (string, optional) – Optional text to include next to the circle.

  • text_args (dictionary, optional) – This dictionary is passed to the MPL text function. By default, it is: {‘color’:’white’}

Examples

>>> # Overplot a white circle of radius 100 kpc over the central galaxy
>>> import yt
>>> ds = yt.load("IsolatedGalaxy/galaxy0030/galaxy0030")
>>> s = yt.SlicePlot(ds, "z", "density")
>>> s.annotate_sphere([0.5, 0.5, 0.5], radius=(100, "kpc"))
>>> s.save()
class yt.visualization.plot_modifications.StreamlineCallback(field_x: tuple[str, str] | str, field_y: tuple[str, str] | str, *, linewidth: float | tuple[str, str] | str = 1.0, linewidth_upscaling: float = 1.0, color: Any | tuple[str, str] | None = None, color_threshold: float | unyt_quantity = -inf, factor: tuple[int, int] | int = 16, field_color=None, display_threshold=None, plot_args=None, **kwargs)[source]

Bases: PlotCallback

Plot streamlines using matplotlib.axes.Axes.streamplot

Parameters:
  • field_x (field key) – The “velocity” analoguous field along the horizontal direction.

  • field_y (field key) – The “velocity” analoguous field along the vertical direction.

  • linewidth (float, or field key (default: 1.0)) – A constant scalar will be passed directly to matplotlib.axes.Axes.streamplot A field key will be first interpreted by yt and produce the adequate 2D array. Data fields are normalized by their maximum value, so the maximal linewidth is 1 by default. See linewidth_upscaling for fine tuning. Note that the absolute value is taken in all cases.

  • linewidth_upscaling (float (default: 1.0)) – A constant multiplicative factor applied to linewidth. Final linewidth is obtained as: linewidth_upscaling * abs(linewidth) / max(abs(linewidth))

  • color (a color identifier, or a field key (default: matplotlib.rcParams['line.color'])) – A constant color identifier will be passed directly to matplotlib.axes.Axes.streamplot A field key will be first interpreted by yt and produce the adequate 2D array. See https://matplotlib.org/stable/api/_as_gen/matplotlib.axes.Axes.streamplot.html for how to customize color mapping using cmap and norm arguments.

  • color_threshold (float or unyt_quantity (default: -inf)) – Regions where the field used for color is lower than this threshold will be masked. Only used if color is a field key.

  • factor (int, or tuple[int, int] (default: 16)) – Fields are downed-sampled by this factor with respect to the background image buffer size. A single integer factor will be used for both direction, but a tuple of 2 integers can be passed to set x and y downsampling independently.

  • **kwargs (any additional keyword arguments will be passed) – directly to matplotlib.axes.Axes.streamplot

class yt.visualization.plot_modifications.TextLabelCallback(pos, text, *, coord_system='data', text_args=None, inset_box_args=None)[source]

Bases: PlotCallback

Overplot text on the plot at a specified position. If you desire an inset box around your text, set one with the inset_box_args dictionary keyword.

Parameters:
  • pos (2- or 3-element tuple, list, or array) – These are the coordinates where the text will be overplotted

  • text (string) – The text you wish to include

  • coord_system (string, optional) –

    This string defines the coordinate system of the coordinates of pos Valid coordinates are:

    ”data” – the 3D dataset coordinates

    ”plot” – the 2D coordinates defined by the actual plot limits

    ”axis” – the MPL axis coordinates: (0,0) is lower left; (1,1) is

    upper right

    ”figure” – the MPL figure coordinates: (0,0) is lower left, (1,1)

    is upper right

  • text_args (dictionary, optional) – This dictionary is passed to the MPL text function for generating the text. By default, it is: {‘color’:’white’} and uses the defaults for the other fonts in the image.

  • inset_box_args (dictionary, optional) – A dictionary of any arbitrary parameters to be passed to the Matplotlib FancyBboxPatch object as the inset box around the text. Default: {}

Examples

>>> # Overplot white text at data location [0.55, 0.7, 0.4]
>>> import yt
>>> ds = yt.load("IsolatedGalaxy/galaxy0030/galaxy0030")
>>> s = yt.SlicePlot(ds, "z", "density")
>>> s.annotate_text([0.55, 0.7, 0.4], "Here is a galaxy")
>>> s.save()
>>> # Overplot yellow text at axis location [0.2, 0.8] with
>>> # a shaded inset box
>>> import yt
>>> ds = yt.load("IsolatedGalaxy/galaxy0030/galaxy0030")
>>> s = yt.SlicePlot(ds, "z", "density")
>>> s.annotate_text(
...     [0.2, 0.8],
...     "Here is a galaxy",
...     coord_system="axis",
...     text_args={"color": "yellow"},
...     inset_box_args={
...         "boxstyle": "square,pad=0.3",
...         "facecolor": "black",
...         "linewidth": 3,
...         "edgecolor": "white",
...         "alpha": 0.5,
...     },
... )
>>> s.save()
class yt.visualization.plot_modifications.TimestampCallback(x_pos=None, y_pos=None, corner='lower_left', *, time=True, redshift=False, time_format='t = {time:.1f} {units}', time_unit=None, redshift_format='z = {redshift:.2f}', draw_inset_box=False, coord_system='axis', time_offset=None, text_args=None, inset_box_args=None)[source]

Bases: PlotCallback

Annotates the timestamp and/or redshift of the data output at a specified location in the image (either in a present corner, or by specifying (x,y) image coordinates with the x_pos, y_pos arguments. If no time_units are specified, it will automatically choose appropriate units. It allows for custom formatting of the time and redshift information, as well as the specification of an inset box around the text.

Parameters:
  • x_pos (floats, optional) – The image location of the timestamp in the coord system defined by the coord_system kwarg. Setting x_pos and y_pos overrides the corner parameter.

  • y_pos (floats, optional) – The image location of the timestamp in the coord system defined by the coord_system kwarg. Setting x_pos and y_pos overrides the corner parameter.

  • corner (string, optional) – Corner sets up one of 4 predeterimined locations for the timestamp to be displayed in the image: ‘upper_left’, ‘upper_right’, ‘lower_left’, ‘lower_right’ (also allows None). This value will be overridden by the optional x_pos and y_pos keywords.

  • time (boolean, optional) – Whether or not to show the ds.current_time of the data output. Can be used solo or in conjunction with redshift parameter.

  • redshift (boolean, optional) – Whether or not to show the ds.current_time of the data output. Can be used solo or in conjunction with the time parameter.

  • time_format (string, optional) – This specifies the format of the time output assuming “time” is the number of time and “unit” is units of the time (e.g. ‘s’, ‘Myr’, etc.) The time can be specified to arbitrary precision according to printf formatting codes (defaults to .1f – a float with 1 digits after decimal). Example: “Age = {time:.2f} {units}”.

  • time_unit (string, optional) – time_unit must be a valid yt time unit (e.g. ‘s’, ‘min’, ‘hr’, ‘yr’, ‘Myr’, etc.)

  • redshift_format (string, optional) – This specifies the format of the redshift output. The redshift can be specified to arbitrary precision according to printf formatting codes (defaults to 0.2f – a float with 2 digits after decimal). Example: “REDSHIFT = {redshift:03.3g}”,

  • draw_inset_box (boolean, optional) – Whether or not an inset box should be included around the text If so, it uses the inset_box_args to set the matplotlib FancyBboxPatch object.

  • coord_system (string, optional) –

    This string defines the coordinate system of the coordinates of pos Valid coordinates are:

    • ”data”: 3D dataset coordinates

    • ”plot”: 2D coordinates defined by the actual plot limits

    • ”axis”: MPL axis coordinates: (0,0) is lower left; (1,1) is upper right

    • ”figure”: MPL figure coordinates: (0,0) is lower left, (1,1) is upper right

  • time_offset (float, (value, unit) tuple, or YTQuantity, optional) – Apply an offset to the time shown in the annotation from the value of the current time. If a scalar value with no units is passed in, the value of the time_unit kwarg is used for the units. Default: None, meaning no offset.

  • text_args (dictionary, optional) – A dictionary of any arbitrary parameters to be passed to the Matplotlib text object. Defaults: {'color':'white', 'horizontalalignment':'center', 'verticalalignment':'top'}.

  • inset_box_args (dictionary, optional) – A dictionary of any arbitrary parameters to be passed to the Matplotlib FancyBboxPatch object as the inset box around the text. Defaults: {'boxstyle':'square', 'pad':0.3, 'facecolor':'black', 'linewidth':3, 'edgecolor':'white', 'alpha':0.5}

Example

>>> import yt
>>> ds = yt.load("Enzo_64/DD0020/data0020")
>>> s = yt.SlicePlot(ds, "z", "density")
>>> s.annotate_timestamp()
class yt.visualization.plot_modifications.TitleCallback(title)[source]

Bases: PlotCallback

Accepts a title and adds it to the plot

class yt.visualization.plot_modifications.TriangleFacetsCallback(triangle_vertices, *, plot_args=None, **kwargs)[source]

Bases: PlotCallback

Intended for representing a slice of a triangular faceted geometry in a slice plot.

Uses a set of triangle_vertices to find all triangles the plane of a SlicePlot intersects with. The lines between the intersection points of the triangles are then added to the plot to create an outline of the geometry represented by the triangles.

class yt.visualization.plot_modifications.VelocityCallback(factor: tuple[int, int] | int = 16, *, scale=None, scale_units=None, normalize=False, plot_args=None, **kwargs)[source]

Bases: PlotCallback

Adds a ‘quiver’ plot of velocity to the plot, skipping all but every factor datapoint. scale is the data units per arrow length unit using scale_units and plot_args allows you to pass in matplotlib arguments (see matplotlib.axes.Axes.quiver for more info). if normalize is True, the velocity fields will be scaled by their local (in-plane) length, allowing morphological features to be more clearly seen for fields with substantial variation in field strength.