# yt.visualization.plot_modifications module¶

Callbacks to add additional functionality on to plots.

class yt.visualization.plot_modifications.ArrowCallback(pos, code_size=None, length=0.03, width=0.0001, head_width=0.01, head_length=0.01, starting_pos=None, coord_system='data', plot_args=None)[source]

Overplot an arrow pointing at a position for highlighting a specific feature. 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 (2- or 3-element tuple, list, or array) – These are the coordinates to which the arrow is pointing 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',
...                  plot_args={'color':'red'})
>>> s.save()

convert_to_plot(plot, coord, offset=True)

Convert coordinates from projected data coordinates to PlotWindow plot coordinates. Projected data coordinates are two dimensional and refer to the location relative to the specific axes being plotted, although still in simulation units. PlotWindow plot coordinates are locations as found in the final plot, usually with the origin in the center of the image and the extent of the image defined by the final plot axis markers.

pixel_scale(plot)
project_coords(plot, coord)

Convert coordinates from simulation data coordinates to projected data coordinates. Simulation data coordinates are three dimensional, and can either be specified as a YTArray or as a list or array in code_length units. Projected data units are 2D versions of the simulation data units relative to the axes of the final plot.

sanitize_coord_system(plot, coord, coord_system)

Given a set of x,y (and z) coordinates and a coordinate system, convert the coordinates (and transformation) ready for final plotting.

Parameters: plot (a PlotMPL subclass) – The plot that we are converting coordinates for coord (array-like) – Coordinates in some coordinate system. coord_system (string) – Possible values include: 'data' 3D data coordinates relative to original dataset 'plot' 2D coordinates as defined by the final axis locations 'axis' 2D coordinates within the axis object from (0,0) in lower left to (1,1) in upper right. Same as matplotlib axis coords. 'figure' 2D coordinates within figure object from (0,0) in lower left to (1,1) in upper right. Same as matplotlib figure coords.
class yt.visualization.plot_modifications.CellEdgesCallback(line_width=0.002, alpha=1.0, color='black')[source]

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

convert_to_plot(plot, coord, offset=True)

Convert coordinates from projected data coordinates to PlotWindow plot coordinates. Projected data coordinates are two dimensional and refer to the location relative to the specific axes being plotted, although still in simulation units. PlotWindow plot coordinates are locations as found in the final plot, usually with the origin in the center of the image and the extent of the image defined by the final plot axis markers.

pixel_scale(plot)
project_coords(plot, coord)

Convert coordinates from simulation data coordinates to projected data coordinates. Simulation data coordinates are three dimensional, and can either be specified as a YTArray or as a list or array in code_length units. Projected data units are 2D versions of the simulation data units relative to the axes of the final plot.

sanitize_coord_system(plot, coord, coord_system)

Given a set of x,y (and z) coordinates and a coordinate system, convert the coordinates (and transformation) ready for final plotting.

Parameters: plot (a PlotMPL subclass) – The plot that we are converting coordinates for coord (array-like) – Coordinates in some coordinate system. coord_system (string) – Possible values include: 'data' 3D data coordinates relative to original dataset 'plot' 2D coordinates as defined by the final axis locations 'axis' 2D coordinates within the axis object from (0,0) in lower left to (1,1) in upper right. Same as matplotlib axis coords. 'figure' 2D coordinates within figure object from (0,0) in lower left to (1,1) in upper right. Same as matplotlib figure coords.
class yt.visualization.plot_modifications.ClumpContourCallback(clumps, plot_args=None)[source]

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

convert_to_plot(plot, coord, offset=True)

Convert coordinates from projected data coordinates to PlotWindow plot coordinates. Projected data coordinates are two dimensional and refer to the location relative to the specific axes being plotted, although still in simulation units. PlotWindow plot coordinates are locations as found in the final plot, usually with the origin in the center of the image and the extent of the image defined by the final plot axis markers.

pixel_scale(plot)
project_coords(plot, coord)

Convert coordinates from simulation data coordinates to projected data coordinates. Simulation data coordinates are three dimensional, and can either be specified as a YTArray or as a list or array in code_length units. Projected data units are 2D versions of the simulation data units relative to the axes of the final plot.

sanitize_coord_system(plot, coord, coord_system)

Given a set of x,y (and z) coordinates and a coordinate system, convert the coordinates (and transformation) ready for final plotting.

Parameters: plot (a PlotMPL subclass) – The plot that we are converting coordinates for coord (array-like) – Coordinates in some coordinate system. coord_system (string) – Possible values include: 'data' 3D data coordinates relative to original dataset 'plot' 2D coordinates as defined by the final axis locations 'axis' 2D coordinates within the axis object from (0,0) in lower left to (1,1) in upper right. Same as matplotlib axis coords. 'figure' 2D coordinates within figure object from (0,0) in lower left to (1,1) in upper right. Same as matplotlib figure coords.
class yt.visualization.plot_modifications.ContourCallback(field, ncont=5, factor=4, clim=None, plot_args=None, label=False, take_log=None, label_args=None, text_args=None, data_source=None)[source]

Add contours in field to the plot. ncont 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.

convert_to_plot(plot, coord, offset=True)

Convert coordinates from projected data coordinates to PlotWindow plot coordinates. Projected data coordinates are two dimensional and refer to the location relative to the specific axes being plotted, although still in simulation units. PlotWindow plot coordinates are locations as found in the final plot, usually with the origin in the center of the image and the extent of the image defined by the final plot axis markers.

pixel_scale(plot)
project_coords(plot, coord)

Convert coordinates from simulation data coordinates to projected data coordinates. Simulation data coordinates are three dimensional, and can either be specified as a YTArray or as a list or array in code_length units. Projected data units are 2D versions of the simulation data units relative to the axes of the final plot.

sanitize_coord_system(plot, coord, coord_system)

Given a set of x,y (and z) coordinates and a coordinate system, convert the coordinates (and transformation) ready for final plotting.

Parameters: plot (a PlotMPL subclass) – The plot that we are converting coordinates for coord (array-like) – Coordinates in some coordinate system. coord_system (string) – Possible values include: 'data' 3D data coordinates relative to original dataset 'plot' 2D coordinates as defined by the final axis locations 'axis' 2D coordinates within the axis object from (0,0) in lower left to (1,1) in upper right. Same as matplotlib axis coords. 'figure' 2D coordinates within figure object from (0,0) in lower left to (1,1) in upper right. Same as matplotlib figure coords.
class yt.visualization.plot_modifications.CuttingQuiverCallback(field_x, field_y, factor=16, scale=None, scale_units=None, normalize=None)[source]

Get a quiver plot on top of a cutting plane, using field_x and field_y, skipping every factor datapoint in the discretization.

convert_to_plot(plot, coord, offset=True)

Convert coordinates from projected data coordinates to PlotWindow plot coordinates. Projected data coordinates are two dimensional and refer to the location relative to the specific axes being plotted, although still in simulation units. PlotWindow plot coordinates are locations as found in the final plot, usually with the origin in the center of the image and the extent of the image defined by the final plot axis markers.

pixel_scale(plot)
project_coords(plot, coord)

Convert coordinates from simulation data coordinates to projected data coordinates. Simulation data coordinates are three dimensional, and can either be specified as a YTArray or as a list or array in code_length units. Projected data units are 2D versions of the simulation data units relative to the axes of the final plot.

sanitize_coord_system(plot, coord, coord_system)

Given a set of x,y (and z) coordinates and a coordinate system, convert the coordinates (and transformation) ready for final plotting.

Parameters: plot (a PlotMPL subclass) – The plot that we are converting coordinates for coord (array-like) – Coordinates in some coordinate system. coord_system (string) – Possible values include: 'data' 3D data coordinates relative to original dataset 'plot' 2D coordinates as defined by the final axis locations 'axis' 2D coordinates within the axis object from (0,0) in lower left to (1,1) in upper right. Same as matplotlib axis coords. 'figure' 2D coordinates within figure object from (0,0) in lower left to (1,1) in upper right. Same as matplotlib figure coords.
class yt.visualization.plot_modifications.GridBoundaryCallback(alpha=0.7, min_pix=1, min_pix_ids=20, draw_ids=False, periodic=True, min_level=None, max_level=None, cmap='B-W LINEAR_r', edgecolors=None, linewidth=1.0)[source]

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 in the corner of the grid. (Not so great in projections...). One can set min and maximum level of grids to display, and can change the linewidth of the displayed grids.

convert_to_plot(plot, coord, offset=True)

Convert coordinates from projected data coordinates to PlotWindow plot coordinates. Projected data coordinates are two dimensional and refer to the location relative to the specific axes being plotted, although still in simulation units. PlotWindow plot coordinates are locations as found in the final plot, usually with the origin in the center of the image and the extent of the image defined by the final plot axis markers.

pixel_scale(plot)
project_coords(plot, coord)

Convert coordinates from simulation data coordinates to projected data coordinates. Simulation data coordinates are three dimensional, and can either be specified as a YTArray or as a list or array in code_length units. Projected data units are 2D versions of the simulation data units relative to the axes of the final plot.

sanitize_coord_system(plot, coord, coord_system)

Given a set of x,y (and z) coordinates and a coordinate system, convert the coordinates (and transformation) ready for final plotting.

Parameters: plot (a PlotMPL subclass) – The plot that we are converting coordinates for coord (array-like) – Coordinates in some coordinate system. coord_system (string) – Possible values include: 'data' 3D data coordinates relative to original dataset 'plot' 2D coordinates as defined by the final axis locations 'axis' 2D coordinates within the axis object from (0,0) in lower left to (1,1) in upper right. Same as matplotlib axis coords. 'figure' 2D coordinates within figure object from (0,0) in lower left to (1,1) in upper right. Same as matplotlib figure coords.
class yt.visualization.plot_modifications.HaloCatalogCallback(halo_catalog, circle_args=None, circle_kwargs=None, width=None, annotate_field=None, radius_field='virial_radius', center_field_prefix='particle_position', text_args=None, font_kwargs=None, factor=1.0)[source]

Plots circles at the locations of all the halos in a halo catalog with radii corresponding to the virial radius of each halo.

circle_args: Contains the arguments controlling the
appearance of the circles, supplied to the Matplotlib patch Circle.
width: the width over which to select halos to plot,
useful when overplotting to a slice plot. Accepts a tuple in the form (1.0, ‘Mpc’).
annotate_field: Accepts a field contained in the
halo catalog to add text to the plot near the halo. Example: annotate_field = ‘particle_mass’ will write the halo mass next to each halo.
radius_field: Accepts a field contained in the halo
catalog to set the radius of the circle which will surround each halo.
center_field_prefix: Accepts a field prefix which will
be used to find the fields containing the coordinates of the center of each halo. Ex: ‘particle_position’ will result in the fields ‘particle_position_x’ for x ‘particle_position_y’ for y, and ‘particle_position_z’ for z.
text_args: Contains the arguments controlling the text
appearance of the annotated field.
factor: A number the virial radius is multiplied by for
plotting the circles. Ex: factor = 2.0 will plot circles with twice the radius of each halo virial radius.
convert_to_plot(plot, coord, offset=True)

Convert coordinates from projected data coordinates to PlotWindow plot coordinates. Projected data coordinates are two dimensional and refer to the location relative to the specific axes being plotted, although still in simulation units. PlotWindow plot coordinates are locations as found in the final plot, usually with the origin in the center of the image and the extent of the image defined by the final plot axis markers.

pixel_scale(plot)
project_coords(plot, coord)

Convert coordinates from simulation data coordinates to projected data coordinates. Simulation data coordinates are three dimensional, and can either be specified as a YTArray or as a list or array in code_length units. Projected data units are 2D versions of the simulation data units relative to the axes of the final plot.

region = None
sanitize_coord_system(plot, coord, coord_system)

Given a set of x,y (and z) coordinates and a coordinate system, convert the coordinates (and transformation) ready for final plotting.

Parameters: plot (a PlotMPL subclass) – The plot that we are converting coordinates for coord (array-like) – Coordinates in some coordinate system. coord_system (string) – Possible values include: 'data' 3D data coordinates relative to original dataset 'plot' 2D coordinates as defined by the final axis locations 'axis' 2D coordinates within the axis object from (0,0) in lower left to (1,1) in upper right. Same as matplotlib axis coords. 'figure' 2D coordinates within figure object from (0,0) in lower left to (1,1) in upper right. Same as matplotlib figure coords.
class yt.visualization.plot_modifications.ImageLineCallback(p1, p2, data_coords=False, coord_system='axis', plot_args=None)[source]

This callback is deprecated, as it is simply a wrapper around the LinePlotCallback (ie annotate_image()). The only difference is that it uses coord_system=”axis” by default. Please see LinePlotCallback for more information.

convert_to_plot(plot, coord, offset=True)

Convert coordinates from projected data coordinates to PlotWindow plot coordinates. Projected data coordinates are two dimensional and refer to the location relative to the specific axes being plotted, although still in simulation units. PlotWindow plot coordinates are locations as found in the final plot, usually with the origin in the center of the image and the extent of the image defined by the final plot axis markers.

pixel_scale(plot)
project_coords(plot, coord)

Convert coordinates from simulation data coordinates to projected data coordinates. Simulation data coordinates are three dimensional, and can either be specified as a YTArray or as a list or array in code_length units. Projected data units are 2D versions of the simulation data units relative to the axes of the final plot.

sanitize_coord_system(plot, coord, coord_system)

Given a set of x,y (and z) coordinates and a coordinate system, convert the coordinates (and transformation) ready for final plotting.

Parameters: plot (a PlotMPL subclass) – The plot that we are converting coordinates for coord (array-like) – Coordinates in some coordinate system. coord_system (string) – Possible values include: 'data' 3D data coordinates relative to original dataset 'plot' 2D coordinates as defined by the final axis locations 'axis' 2D coordinates within the axis object from (0,0) in lower left to (1,1) in upper right. Same as matplotlib axis coords. 'figure' 2D coordinates within figure object from (0,0) in lower left to (1,1) in upper right. Same as matplotlib figure coords.
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]

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_y (field_x,) – 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))

convert_to_plot(plot, coord, offset=True)

Convert coordinates from projected data coordinates to PlotWindow plot coordinates. Projected data coordinates are two dimensional and refer to the location relative to the specific axes being plotted, although still in simulation units. PlotWindow plot coordinates are locations as found in the final plot, usually with the origin in the center of the image and the extent of the image defined by the final plot axis markers.

pixel_scale(plot)
project_coords(plot, coord)

Convert coordinates from simulation data coordinates to projected data coordinates. Simulation data coordinates are three dimensional, and can either be specified as a YTArray or as a list or array in code_length units. Projected data units are 2D versions of the simulation data units relative to the axes of the final plot.

sanitize_coord_system(plot, coord, coord_system)

Given a set of x,y (and z) coordinates and a coordinate system, convert the coordinates (and transformation) ready for final plotting.

Parameters: plot (a PlotMPL subclass) – The plot that we are converting coordinates for coord (array-like) – Coordinates in some coordinate system. coord_system (string) – Possible values include: 'data' 3D data coordinates relative to original dataset 'plot' 2D coordinates as defined by the final axis locations 'axis' 2D coordinates within the axis object from (0,0) in lower left to (1,1) in upper right. Same as matplotlib axis coords. 'figure' 2D coordinates within figure object from (0,0) in lower left to (1,1) in upper right. Same as matplotlib figure coords.
class yt.visualization.plot_modifications.LinePlotCallback(p1, p2, data_coords=False, coord_system='data', plot_args=None)[source]

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: p2 (p1,) – 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',
plot_args={'color':'red', 'lineStyles':'--'})
>>> s.save()

convert_to_plot(plot, coord, offset=True)

Convert coordinates from projected data coordinates to PlotWindow plot coordinates. Projected data coordinates are two dimensional and refer to the location relative to the specific axes being plotted, although still in simulation units. PlotWindow plot coordinates are locations as found in the final plot, usually with the origin in the center of the image and the extent of the image defined by the final plot axis markers.

pixel_scale(plot)
project_coords(plot, coord)

Convert coordinates from simulation data coordinates to projected data coordinates. Simulation data coordinates are three dimensional, and can either be specified as a YTArray or as a list or array in code_length units. Projected data units are 2D versions of the simulation data units relative to the axes of the final plot.

sanitize_coord_system(plot, coord, coord_system)

Given a set of x,y (and z) coordinates and a coordinate system, convert the coordinates (and transformation) ready for final plotting.

Parameters: plot (a PlotMPL subclass) – The plot that we are converting coordinates for coord (array-like) – Coordinates in some coordinate system. coord_system (string) – Possible values include: 'data' 3D data coordinates relative to original dataset 'plot' 2D coordinates as defined by the final axis locations 'axis' 2D coordinates within the axis object from (0,0) in lower left to (1,1) in upper right. Same as matplotlib axis coords. 'figure' 2D coordinates within figure object from (0,0) in lower left to (1,1) in upper right. Same as matplotlib figure coords.
class yt.visualization.plot_modifications.MagFieldCallback(factor=16, scale=None, scale_units=None, normalize=False)[source]

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

convert_to_plot(plot, coord, offset=True)

Convert coordinates from projected data coordinates to PlotWindow plot coordinates. Projected data coordinates are two dimensional and refer to the location relative to the specific axes being plotted, although still in simulation units. PlotWindow plot coordinates are locations as found in the final plot, usually with the origin in the center of the image and the extent of the image defined by the final plot axis markers.

pixel_scale(plot)
project_coords(plot, coord)

Convert coordinates from simulation data coordinates to projected data coordinates. Simulation data coordinates are three dimensional, and can either be specified as a YTArray or as a list or array in code_length units. Projected data units are 2D versions of the simulation data units relative to the axes of the final plot.

sanitize_coord_system(plot, coord, coord_system)

Given a set of x,y (and z) coordinates and a coordinate system, convert the coordinates (and transformation) ready for final plotting.

Parameters: plot (a PlotMPL subclass) – The plot that we are converting coordinates for coord (array-like) – Coordinates in some coordinate system. coord_system (string) – Possible values include: 'data' 3D data coordinates relative to original dataset 'plot' 2D coordinates as defined by the final axis locations 'axis' 2D coordinates within the axis object from (0,0) in lower left to (1,1) in upper right. Same as matplotlib axis coords. 'figure' 2D coordinates within figure object from (0,0) in lower left to (1,1) in upper right. Same as matplotlib figure coords.
class yt.visualization.plot_modifications.MarkerAnnotateCallback(pos, marker='x', coord_system='data', plot_args=None)[source]

Overplot a marker on a position for highlighting specific features.

Parameters: pos (2- or 3-element tuple, list, or array) – These are the coordinates where the marker will be overplotted 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',
...                   plot_args={'color':'yellow', 's':200})
>>> s.save()

convert_to_plot(plot, coord, offset=True)

Convert coordinates from projected data coordinates to PlotWindow plot coordinates. Projected data coordinates are two dimensional and refer to the location relative to the specific axes being plotted, although still in simulation units. PlotWindow plot coordinates are locations as found in the final plot, usually with the origin in the center of the image and the extent of the image defined by the final plot axis markers.

pixel_scale(plot)
project_coords(plot, coord)

Convert coordinates from simulation data coordinates to projected data coordinates. Simulation data coordinates are three dimensional, and can either be specified as a YTArray or as a list or array in code_length units. Projected data units are 2D versions of the simulation data units relative to the axes of the final plot.

sanitize_coord_system(plot, coord, coord_system)

Given a set of x,y (and z) coordinates and a coordinate system, convert the coordinates (and transformation) ready for final plotting.

Parameters: plot (a PlotMPL subclass) – The plot that we are converting coordinates for coord (array-like) – Coordinates in some coordinate system. coord_system (string) – Possible values include: 'data' 3D data coordinates relative to original dataset 'plot' 2D coordinates as defined by the final axis locations 'axis' 2D coordinates within the axis object from (0,0) in lower left to (1,1) in upper right. Same as matplotlib axis coords. 'figure' 2D coordinates within figure object from (0,0) in lower left to (1,1) in upper right. Same as matplotlib figure coords.
class yt.visualization.plot_modifications.MeshLinesCallback(plot_args=None)[source]

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(plot_args={'color':'black'})

convert_to_plot(plot, coord, offset=True)

Convert coordinates from projected data coordinates to PlotWindow plot coordinates. Projected data coordinates are two dimensional and refer to the location relative to the specific axes being plotted, although still in simulation units. PlotWindow plot coordinates are locations as found in the final plot, usually with the origin in the center of the image and the extent of the image defined by the final plot axis markers.

pixel_scale(plot)
project_coords(plot, coord)

Convert coordinates from simulation data coordinates to projected data coordinates. Simulation data coordinates are three dimensional, and can either be specified as a YTArray or as a list or array in code_length units. Projected data units are 2D versions of the simulation data units relative to the axes of the final plot.

promote_2d_to_3d(coords, indices, plot)[source]
sanitize_coord_system(plot, coord, coord_system)

Given a set of x,y (and z) coordinates and a coordinate system, convert the coordinates (and transformation) ready for final plotting.

Parameters: plot (a PlotMPL subclass) – The plot that we are converting coordinates for coord (array-like) – Coordinates in some coordinate system. coord_system (string) – Possible values include: 'data' 3D data coordinates relative to original dataset 'plot' 2D coordinates as defined by the final axis locations 'axis' 2D coordinates within the axis object from (0,0) in lower left to (1,1) in upper right. Same as matplotlib axis coords. 'figure' 2D coordinates within figure object from (0,0) in lower left to (1,1) in upper right. Same as matplotlib figure coords.
class yt.visualization.plot_modifications.ParticleCallback(width, p_size=1.0, col='k', marker='o', stride=1, ptype='all', minimum_mass=None, alpha=1.0)[source]

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. Particles with masses below minimum_mass will not be plotted. alpha determines the opacity of the marker symbol used in the scatter plot.

convert_to_plot(plot, coord, offset=True)

Convert coordinates from projected data coordinates to PlotWindow plot coordinates. Projected data coordinates are two dimensional and refer to the location relative to the specific axes being plotted, although still in simulation units. PlotWindow plot coordinates are locations as found in the final plot, usually with the origin in the center of the image and the extent of the image defined by the final plot axis markers.

pixel_scale(plot)
project_coords(plot, coord)

Convert coordinates from simulation data coordinates to projected data coordinates. Simulation data coordinates are three dimensional, and can either be specified as a YTArray or as a list or array in code_length units. Projected data units are 2D versions of the simulation data units relative to the axes of the final plot.

region = None
sanitize_coord_system(plot, coord, coord_system)

Given a set of x,y (and z) coordinates and a coordinate system, convert the coordinates (and transformation) ready for final plotting.

Parameters: plot (a PlotMPL subclass) – The plot that we are converting coordinates for coord (array-like) – Coordinates in some coordinate system. coord_system (string) – Possible values include: 'data' 3D data coordinates relative to original dataset 'plot' 2D coordinates as defined by the final axis locations 'axis' 2D coordinates within the axis object from (0,0) in lower left to (1,1) in upper right. Same as matplotlib axis coords. 'figure' 2D coordinates within figure object from (0,0) in lower left to (1,1) in upper right. Same as matplotlib figure coords.
class yt.visualization.plot_modifications.PlotCallback(*args, **kwargs)[source]

Bases: object

convert_to_plot(plot, coord, offset=True)[source]

Convert coordinates from projected data coordinates to PlotWindow plot coordinates. Projected data coordinates are two dimensional and refer to the location relative to the specific axes being plotted, although still in simulation units. PlotWindow plot coordinates are locations as found in the final plot, usually with the origin in the center of the image and the extent of the image defined by the final plot axis markers.

pixel_scale(plot)[source]
project_coords(plot, coord)[source]

Convert coordinates from simulation data coordinates to projected data coordinates. Simulation data coordinates are three dimensional, and can either be specified as a YTArray or as a list or array in code_length units. Projected data units are 2D versions of the simulation data units relative to the axes of the final plot.

sanitize_coord_system(plot, coord, coord_system)[source]

Given a set of x,y (and z) coordinates and a coordinate system, convert the coordinates (and transformation) ready for final plotting.

Parameters: plot (a PlotMPL subclass) – The plot that we are converting coordinates for coord (array-like) – Coordinates in some coordinate system. coord_system (string) – Possible values include: 'data' 3D data coordinates relative to original dataset 'plot' 2D coordinates as defined by the final axis locations 'axis' 2D coordinates within the axis object from (0,0) in lower left to (1,1) in upper right. Same as matplotlib axis coords. 'figure' 2D coordinates within figure object from (0,0) in lower left to (1,1) in upper right. Same as matplotlib figure coords.
class yt.visualization.plot_modifications.PointAnnotateCallback(pos, text, data_coords=False, coord_system='data', text_args=None, inset_box_args=None)[source]

This callback is deprecated, as it is simply a wrapper around the TextLabelCallback (ie annotate_text()). Please see TextLabelCallback for more information.

convert_to_plot(plot, coord, offset=True)

Convert coordinates from projected data coordinates to PlotWindow plot coordinates. Projected data coordinates are two dimensional and refer to the location relative to the specific axes being plotted, although still in simulation units. PlotWindow plot coordinates are locations as found in the final plot, usually with the origin in the center of the image and the extent of the image defined by the final plot axis markers.

pixel_scale(plot)
project_coords(plot, coord)

Convert coordinates from simulation data coordinates to projected data coordinates. Simulation data coordinates are three dimensional, and can either be specified as a YTArray or as a list or array in code_length units. Projected data units are 2D versions of the simulation data units relative to the axes of the final plot.

sanitize_coord_system(plot, coord, coord_system)

Given a set of x,y (and z) coordinates and a coordinate system, convert the coordinates (and transformation) ready for final plotting.

Parameters: plot (a PlotMPL subclass) – The plot that we are converting coordinates for coord (array-like) – Coordinates in some coordinate system. coord_system (string) – Possible values include: 'data' 3D data coordinates relative to original dataset 'plot' 2D coordinates as defined by the final axis locations 'axis' 2D coordinates within the axis object from (0,0) in lower left to (1,1) in upper right. Same as matplotlib axis coords. 'figure' 2D coordinates within figure object from (0,0) in lower left to (1,1) in upper right. Same as matplotlib figure coords.
class yt.visualization.plot_modifications.QuiverCallback(field_x, field_y, factor=16, scale=None, scale_units=None, normalize=False, bv_x=0, bv_y=0)[source]

Adds a ‘quiver’ plot to any plot, using the field_x and field_y from the associated data, skipping every factor datapoints scale is the data units per arrow length unit using scale_units (see matplotlib.axes.Axes.quiver for more info)

convert_to_plot(plot, coord, offset=True)

Convert coordinates from projected data coordinates to PlotWindow plot coordinates. Projected data coordinates are two dimensional and refer to the location relative to the specific axes being plotted, although still in simulation units. PlotWindow plot coordinates are locations as found in the final plot, usually with the origin in the center of the image and the extent of the image defined by the final plot axis markers.

pixel_scale(plot)
project_coords(plot, coord)

Convert coordinates from simulation data coordinates to projected data coordinates. Simulation data coordinates are three dimensional, and can either be specified as a YTArray or as a list or array in code_length units. Projected data units are 2D versions of the simulation data units relative to the axes of the final plot.

sanitize_coord_system(plot, coord, coord_system)

Given a set of x,y (and z) coordinates and a coordinate system, convert the coordinates (and transformation) ready for final plotting.

Parameters: plot (a PlotMPL subclass) – The plot that we are converting coordinates for coord (array-like) – Coordinates in some coordinate system. coord_system (string) – Possible values include: 'data' 3D data coordinates relative to original dataset 'plot' 2D coordinates as defined by the final axis locations 'axis' 2D coordinates within the axis object from (0,0) in lower left to (1,1) in upper right. Same as matplotlib axis coords. 'figure' 2D coordinates within figure object from (0,0) in lower left to (1,1) in upper right. Same as matplotlib figure coords.
class yt.visualization.plot_modifications.RayCallback(ray, arrow=False, plot_args=None)[source]

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 analysis_modules.cosmological_observation.light_ray.light_ray.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 yt.analysis_modules.cosmological_observation.api 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()

convert_to_plot(plot, coord, offset=True)

Convert coordinates from projected data coordinates to PlotWindow plot coordinates. Projected data coordinates are two dimensional and refer to the location relative to the specific axes being plotted, although still in simulation units. PlotWindow plot coordinates are locations as found in the final plot, usually with the origin in the center of the image and the extent of the image defined by the final plot axis markers.

pixel_scale(plot)
project_coords(plot, coord)

Convert coordinates from simulation data coordinates to projected data coordinates. Simulation data coordinates are three dimensional, and can either be specified as a YTArray or as a list or array in code_length units. Projected data units are 2D versions of the simulation data units relative to the axes of the final plot.

sanitize_coord_system(plot, coord, coord_system)

Given a set of x,y (and z) coordinates and a coordinate system, convert the coordinates (and transformation) ready for final plotting.

Parameters: plot (a PlotMPL subclass) – The plot that we are converting coordinates for coord (array-like) – Coordinates in some coordinate system. coord_system (string) – Possible values include: 'data' 3D data coordinates relative to original dataset 'plot' 2D coordinates as defined by the final axis locations 'axis' 2D coordinates within the axis object from (0,0) in lower left to (1,1) in upper right. Same as matplotlib axis coords. 'figure' 2D coordinates within figure object from (0,0) in lower left to (1,1) in upper right. Same as matplotlib figure coords.
class yt.visualization.plot_modifications.RegisteredCallback(name, b, d)[source]

Bases: type

mro() → list

return a type’s method resolution order

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

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. max_frac (min_frac,) – 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” – 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) – 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'}

Example

>>> import yt
>>> ds = yt.load('Enzo_64/DD0020/data0020')
>>> s = yt.SlicePlot(ds, 'z', 'density')
>>> s.annotate_scale()

convert_to_plot(plot, coord, offset=True)

Convert coordinates from projected data coordinates to PlotWindow plot coordinates. Projected data coordinates are two dimensional and refer to the location relative to the specific axes being plotted, although still in simulation units. PlotWindow plot coordinates are locations as found in the final plot, usually with the origin in the center of the image and the extent of the image defined by the final plot axis markers.

pixel_scale(plot)
project_coords(plot, coord)

Convert coordinates from simulation data coordinates to projected data coordinates. Simulation data coordinates are three dimensional, and can either be specified as a YTArray or as a list or array in code_length units. Projected data units are 2D versions of the simulation data units relative to the axes of the final plot.

sanitize_coord_system(plot, coord, coord_system)

Given a set of x,y (and z) coordinates and a coordinate system, convert the coordinates (and transformation) ready for final plotting.

Parameters: plot (a PlotMPL subclass) – The plot that we are converting coordinates for coord (array-like) – Coordinates in some coordinate system. coord_system (string) – Possible values include: 'data' 3D data coordinates relative to original dataset 'plot' 2D coordinates as defined by the final axis locations 'axis' 2D coordinates within the axis object from (0,0) in lower left to (1,1) in upper right. Same as matplotlib axis coords. 'figure' 2D coordinates within figure object from (0,0) in lower left to (1,1) in upper right. Same as matplotlib figure coords.
class yt.visualization.plot_modifications.SphereCallback(center, radius, circle_args=None, text=None, coord_system='data', text_args=None)[source]

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

convert_to_plot(plot, coord, offset=True)

Convert coordinates from projected data coordinates to PlotWindow plot coordinates. Projected data coordinates are two dimensional and refer to the location relative to the specific axes being plotted, although still in simulation units. PlotWindow plot coordinates are locations as found in the final plot, usually with the origin in the center of the image and the extent of the image defined by the final plot axis markers.

pixel_scale(plot)
project_coords(plot, coord)

Convert coordinates from simulation data coordinates to projected data coordinates. Simulation data coordinates are three dimensional, and can either be specified as a YTArray or as a list or array in code_length units. Projected data units are 2D versions of the simulation data units relative to the axes of the final plot.

sanitize_coord_system(plot, coord, coord_system)

Given a set of x,y (and z) coordinates and a coordinate system, convert the coordinates (and transformation) ready for final plotting.

Parameters: plot (a PlotMPL subclass) – The plot that we are converting coordinates for coord (array-like) – Coordinates in some coordinate system. coord_system (string) – Possible values include: 'data' 3D data coordinates relative to original dataset 'plot' 2D coordinates as defined by the final axis locations 'axis' 2D coordinates within the axis object from (0,0) in lower left to (1,1) in upper right. Same as matplotlib axis coords. 'figure' 2D coordinates within figure object from (0,0) in lower left to (1,1) in upper right. Same as matplotlib figure coords.
class yt.visualization.plot_modifications.StreamlineCallback(field_x, field_y, factor=16, density=1, field_color=None, plot_args=None)[source]

Add streamlines to any plot, using the field_x and field_y from the associated data, skipping every factor datapoints like ‘quiver’. density is the index of the amount of the streamlines. field_color is a field to be used to colormap the streamlines.

convert_to_plot(plot, coord, offset=True)

Convert coordinates from projected data coordinates to PlotWindow plot coordinates. Projected data coordinates are two dimensional and refer to the location relative to the specific axes being plotted, although still in simulation units. PlotWindow plot coordinates are locations as found in the final plot, usually with the origin in the center of the image and the extent of the image defined by the final plot axis markers.

pixel_scale(plot)
project_coords(plot, coord)

Convert coordinates from simulation data coordinates to projected data coordinates. Simulation data coordinates are three dimensional, and can either be specified as a YTArray or as a list or array in code_length units. Projected data units are 2D versions of the simulation data units relative to the axes of the final plot.

sanitize_coord_system(plot, coord, coord_system)

Given a set of x,y (and z) coordinates and a coordinate system, convert the coordinates (and transformation) ready for final plotting.

Parameters: plot (a PlotMPL subclass) – The plot that we are converting coordinates for coord (array-like) – Coordinates in some coordinate system. coord_system (string) – Possible values include: 'data' 3D data coordinates relative to original dataset 'plot' 2D coordinates as defined by the final axis locations 'axis' 2D coordinates within the axis object from (0,0) in lower left to (1,1) in upper right. Same as matplotlib axis coords. 'figure' 2D coordinates within figure object from (0,0) in lower left to (1,1) in upper right. Same as matplotlib figure coords.
class yt.visualization.plot_modifications.TextLabelCallback(pos, text, data_coords=False, coord_system='data', text_args=None, inset_box_args=None)[source]

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'},
...                                 'facecolor':'black',
...                                 'linewidth':3,
...                                 'edgecolor':'white', 'alpha':0.5})
>>> s.save()

convert_to_plot(plot, coord, offset=True)

Convert coordinates from projected data coordinates to PlotWindow plot coordinates. Projected data coordinates are two dimensional and refer to the location relative to the specific axes being plotted, although still in simulation units. PlotWindow plot coordinates are locations as found in the final plot, usually with the origin in the center of the image and the extent of the image defined by the final plot axis markers.

pixel_scale(plot)
project_coords(plot, coord)

Convert coordinates from simulation data coordinates to projected data coordinates. Simulation data coordinates are three dimensional, and can either be specified as a YTArray or as a list or array in code_length units. Projected data units are 2D versions of the simulation data units relative to the axes of the final plot.

sanitize_coord_system(plot, coord, coord_system)

Given a set of x,y (and z) coordinates and a coordinate system, convert the coordinates (and transformation) ready for final plotting.

Parameters: plot (a PlotMPL subclass) – The plot that we are converting coordinates for coord (array-like) – Coordinates in some coordinate system. coord_system (string) – Possible values include: 'data' 3D data coordinates relative to original dataset 'plot' 2D coordinates as defined by the final axis locations 'axis' 2D coordinates within the axis object from (0,0) in lower left to (1,1) in upper right. Same as matplotlib axis coords. 'figure' 2D coordinates within figure object from (0,0) in lower left to (1,1) in upper right. Same as matplotlib figure coords.
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', text_args=None, inset_box_args=None)[source]

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: y_pos (x_pos,) – 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” – 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) – 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()

convert_to_plot(plot, coord, offset=True)

Convert coordinates from projected data coordinates to PlotWindow plot coordinates. Projected data coordinates are two dimensional and refer to the location relative to the specific axes being plotted, although still in simulation units. PlotWindow plot coordinates are locations as found in the final plot, usually with the origin in the center of the image and the extent of the image defined by the final plot axis markers.

pixel_scale(plot)
project_coords(plot, coord)

Convert coordinates from simulation data coordinates to projected data coordinates. Simulation data coordinates are three dimensional, and can either be specified as a YTArray or as a list or array in code_length units. Projected data units are 2D versions of the simulation data units relative to the axes of the final plot.

sanitize_coord_system(plot, coord, coord_system)

Given a set of x,y (and z) coordinates and a coordinate system, convert the coordinates (and transformation) ready for final plotting.

Parameters: plot (a PlotMPL subclass) – The plot that we are converting coordinates for coord (array-like) – Coordinates in some coordinate system. coord_system (string) – Possible values include: 'data' 3D data coordinates relative to original dataset 'plot' 2D coordinates as defined by the final axis locations 'axis' 2D coordinates within the axis object from (0,0) in lower left to (1,1) in upper right. Same as matplotlib axis coords. 'figure' 2D coordinates within figure object from (0,0) in lower left to (1,1) in upper right. Same as matplotlib figure coords.
class yt.visualization.plot_modifications.TitleCallback(title)[source]

Accepts a title and adds it to the plot

convert_to_plot(plot, coord, offset=True)

Convert coordinates from projected data coordinates to PlotWindow plot coordinates. Projected data coordinates are two dimensional and refer to the location relative to the specific axes being plotted, although still in simulation units. PlotWindow plot coordinates are locations as found in the final plot, usually with the origin in the center of the image and the extent of the image defined by the final plot axis markers.

pixel_scale(plot)
project_coords(plot, coord)

Convert coordinates from simulation data coordinates to projected data coordinates. Simulation data coordinates are three dimensional, and can either be specified as a YTArray or as a list or array in code_length units. Projected data units are 2D versions of the simulation data units relative to the axes of the final plot.

sanitize_coord_system(plot, coord, coord_system)

Given a set of x,y (and z) coordinates and a coordinate system, convert the coordinates (and transformation) ready for final plotting.

Parameters: plot (a PlotMPL subclass) – The plot that we are converting coordinates for coord (array-like) – Coordinates in some coordinate system. coord_system (string) – Possible values include: 'data' 3D data coordinates relative to original dataset 'plot' 2D coordinates as defined by the final axis locations 'axis' 2D coordinates within the axis object from (0,0) in lower left to (1,1) in upper right. Same as matplotlib axis coords. 'figure' 2D coordinates within figure object from (0,0) in lower left to (1,1) in upper right. Same as matplotlib figure coords.
class yt.visualization.plot_modifications.TriangleFacetsCallback(triangle_vertices, plot_args=None)[source]

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.

convert_to_plot(plot, coord, offset=True)

Convert coordinates from projected data coordinates to PlotWindow plot coordinates. Projected data coordinates are two dimensional and refer to the location relative to the specific axes being plotted, although still in simulation units. PlotWindow plot coordinates are locations as found in the final plot, usually with the origin in the center of the image and the extent of the image defined by the final plot axis markers.

pixel_scale(plot)
project_coords(plot, coord)

Convert coordinates from simulation data coordinates to projected data coordinates. Simulation data coordinates are three dimensional, and can either be specified as a YTArray or as a list or array in code_length units. Projected data units are 2D versions of the simulation data units relative to the axes of the final plot.

sanitize_coord_system(plot, coord, coord_system)

Given a set of x,y (and z) coordinates and a coordinate system, convert the coordinates (and transformation) ready for final plotting.

Parameters: plot (a PlotMPL subclass) – The plot that we are converting coordinates for coord (array-like) – Coordinates in some coordinate system. coord_system (string) – Possible values include: 'data' 3D data coordinates relative to original dataset 'plot' 2D coordinates as defined by the final axis locations 'axis' 2D coordinates within the axis object from (0,0) in lower left to (1,1) in upper right. Same as matplotlib axis coords. 'figure' 2D coordinates within figure object from (0,0) in lower left to (1,1) in upper right. Same as matplotlib figure coords.
class yt.visualization.plot_modifications.VelocityCallback(factor=16, scale=None, scale_units=None, normalize=False)[source]

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

convert_to_plot(plot, coord, offset=True)

Convert coordinates from projected data coordinates to PlotWindow plot coordinates. Projected data coordinates are two dimensional and refer to the location relative to the specific axes being plotted, although still in simulation units. PlotWindow plot coordinates are locations as found in the final plot, usually with the origin in the center of the image and the extent of the image defined by the final plot axis markers.

pixel_scale(plot)
project_coords(plot, coord)

Convert coordinates from simulation data coordinates to projected data coordinates. Simulation data coordinates are three dimensional, and can either be specified as a YTArray or as a list or array in code_length units. Projected data units are 2D versions of the simulation data units relative to the axes of the final plot.

sanitize_coord_system(plot, coord, coord_system)

Given a set of x,y (and z) coordinates and a coordinate system, convert the coordinates (and transformation) ready for final plotting.

Parameters: plot (a PlotMPL subclass) – The plot that we are converting coordinates for coord (array-like) – Coordinates in some coordinate system. coord_system (string) – Possible values include: 'data' 3D data coordinates relative to original dataset 'plot' 2D coordinates as defined by the final axis locations 'axis' 2D coordinates within the axis object from (0,0) in lower left to (1,1) in upper right. Same as matplotlib axis coords. 'figure' 2D coordinates within figure object from (0,0) in lower left to (1,1) in upper right. Same as matplotlib figure coords.