yt.visualization.profile_plotter module¶
-
class
yt.visualization.profile_plotter.
AxesContainer
(plots)[source]¶ Bases:
collections.OrderedDict
-
clear
() → None. Remove all items from od.¶
-
copy
() → a shallow copy of od¶
-
fromkeys
(value=None)¶ Create a new ordered dictionary with keys from iterable and values set to value.
-
get
(key, default=None, /)¶ Return the value for key if key is in the dictionary, else default.
-
items
() → a set-like object providing a view on D’s items¶
-
keys
() → a set-like object providing a view on D’s keys¶
-
move_to_end
(key, last=True)¶ Move an existing element to the end (or beginning if last is false).
Raise KeyError if the element does not exist.
-
pop
(k[, d]) → v, remove specified key and return the corresponding¶ value. If key is not found, d is returned if given, otherwise KeyError is raised.
-
popitem
(last=True)¶ Remove and return a (key, value) pair from the dictionary.
Pairs are returned in LIFO order if last is true or FIFO order if false.
-
setdefault
(key, default=None)¶ Insert key with a value of default if key is not in the dictionary.
Return the value for key if key is in the dictionary, else default.
-
update
([E, ]**F) → None. Update D from dict/iterable E and F.¶ If E is present and has a .keys() method, then does: for k in E: D[k] = E[k] If E is present and lacks a .keys() method, then does: for k, v in E: D[k] = v In either case, this is followed by: for k in F: D[k] = F[k]
-
values
() → an object providing a view on D’s values¶
-
-
class
yt.visualization.profile_plotter.
FigureContainer
(plots)[source]¶ Bases:
collections.OrderedDict
-
clear
() → None. Remove all items from od.¶
-
copy
() → a shallow copy of od¶
-
fromkeys
(value=None)¶ Create a new ordered dictionary with keys from iterable and values set to value.
-
get
(key, default=None, /)¶ Return the value for key if key is in the dictionary, else default.
-
items
() → a set-like object providing a view on D’s items¶
-
keys
() → a set-like object providing a view on D’s keys¶
-
move_to_end
(key, last=True)¶ Move an existing element to the end (or beginning if last is false).
Raise KeyError if the element does not exist.
-
pop
(k[, d]) → v, remove specified key and return the corresponding¶ value. If key is not found, d is returned if given, otherwise KeyError is raised.
-
popitem
(last=True)¶ Remove and return a (key, value) pair from the dictionary.
Pairs are returned in LIFO order if last is true or FIFO order if false.
-
setdefault
(key, default=None)¶ Insert key with a value of default if key is not in the dictionary.
Return the value for key if key is in the dictionary, else default.
-
update
([E, ]**F) → None. Update D from dict/iterable E and F.¶ If E is present and has a .keys() method, then does: for k in E: D[k] = E[k] If E is present and lacks a .keys() method, then does: for k, v in E: D[k] = v In either case, this is followed by: for k in F: D[k] = F[k]
-
values
() → an object providing a view on D’s values¶
-
-
class
yt.visualization.profile_plotter.
PhasePlot
(data_source, x_field, y_field, z_fields, weight_field='gas', 'mass', x_bins=128, y_bins=128, accumulation=False, fractional=False, fontsize=18, figure_size=8.0, shading='nearest')[source]¶ Bases:
yt.visualization.plot_container.ImagePlotContainer
Create a 2d profile (phase) plot from a data source or from profile object created with yt.data_objects.profiles.create_profile.
Given a data object (all_data, region, sphere, etc.), an x field, y field, and z field (or fields), this will create a two-dimensional profile of the average (or total) value of the z field in bins of the x and y fields.
- Parameters
data_source (YTSelectionContainer Object) – The data object to be profiled, such as all_data, region, or sphere. If a dataset is passed in instead, an all_data data object is generated internally from the dataset.
x_field (str) – The x binning field for the profile.
y_field (str) – The y binning field for the profile.
z_fields (str or list) – The field or fields to be profiled.
weight_field (str) – The weight field for calculating weighted averages. If None, the profile values are the sum of the field values within the bin. Otherwise, the values are a weighted average. Default : (“gas”, “mass”)
x_bins (int) – The number of bins in x field for the profile. Default: 128.
y_bins (int) – The number of bins in y field for the profile. Default: 128.
accumulation (bool or list of bools) – If True, the profile values for a bin n are the cumulative sum of all the values from bin 0 to n. If -True, the sum is reversed so that the value for bin n is the cumulative sum from bin N (total bins) to n. A list of values can be given to control the summation in each dimension independently. Default: False.
fractional (If True the profile values are divided by the sum of all) – the profile data such that the profile represents a probability distribution function.
fontsize (int) – Font size for all text in the plot. Default: 18.
figure_size (int) – Size in inches of the image. Default: 8 (8x8)
shading (str) – This argument is directly passed down to matplotlib.axes.Axes.pcolormesh see https://matplotlib.org/3.3.1/gallery/images_contours_and_fields/pcolormesh_grids.html#sphx-glr-gallery-images-contours-and-fields-pcolormesh-grids-py # noqa Default: ‘nearest’
Examples
>>> import yt >>> ds = yt.load("enzo_tiny_cosmology/DD0046/DD0046") >>> ad = ds.all_data() >>> plot = yt.PhasePlot( ... ad, ... ("gas", "density"), ... ("gas", "temperature"), ... [("gas", "mass")], ... weight_field=None, ... ) >>> plot.save()
>>> # Change plot properties. >>> plot.set_cmap(("gas", "mass"), "jet") >>> plot.set_zlim(("gas", "mass"), 1e8, 1e13) >>> plot.annotate_title("This is a phase plot")
-
annotate_text
(xpos=0.0, ypos=0.0, text=None, **text_kwargs)[source]¶ Allow the user to insert text onto the plot The x-position and y-position must be given as well as the text string. Add text tp plot at location xpos, ypos in plot coordinates (see example below).
-
annotate_title
(title)[source]¶ Set a title for the plot.
- Parameters
title (str) – The title to add.
Examples
>>> plot.annotate_title("This is a phase plot")
-
display
(name=None, mpl_kwargs=None)¶ Will attempt to show the plot in in an IPython notebook. Failing that, the plot will be saved to disk.
-
property
fields
¶
-
classmethod
from_profile
(profile, fontsize=18, figure_size=8.0, shading='nearest')[source]¶ Instantiate a PhasePlot object from a profile object created with
create_profile()
.- Parameters
profile (An instance of
ProfileND
) – A single profile object.fontsize (float) – The fontsize to use, in points.
figure_size (float) – The figure size to use, in inches.
shading (str) – This argument is directly passed down to matplotlib.axes.Axes.pcolormesh see https://matplotlib.org/3.3.1/gallery/images_contours_and_fields/pcolormesh_grids.html#sphx-glr-gallery-images-contours-and-fields-pcolormesh-grids-py # noqa Default: ‘nearest’
Examples
>>> import yt >>> ds = yt.load("IsolatedGalaxy/galaxy0030/galaxy0030") >>> extrema = { ... ("gas", "density"): (1e-31, 1e-24), ... ("gas", "temperature"): (1e1, 1e8), ... ("gas", "mass"): (1e-6, 1e-1), ... } >>> profile = yt.create_profile( ... ds.all_data(), ... [("gas", "density"), ("gas", "temperature")], ... fields=[("gas", "mass")], ... extrema=extrema, ... fractional=True, ... ) >>> ph = yt.PhasePlot.from_profile(profile) >>> ph.save()
-
get_log
(field)¶ get the transform type of a field.
- Parameters
field (string) – the field to get a transform if field == ‘all’, applies to all plots.
-
hide_axes
(field=None, draw_frame=False)¶ Hides the axes for a plot and updates the size of the plot accordingly. Defaults to operating on all fields for a PlotContainer object.
- Parameters
field (string, field tuple, or list of strings or field tuples (optional)) – The name of the field(s) that we want to hide the axes.
draw_frame (boolean) – If True, the axes frame will still be drawn. Defaults to False. See note below for more details.
Examples
This will save an image with no axes.
>>> import yt >>> ds = yt.load("IsolatedGalaxy/galaxy0030/galaxy0030") >>> s = SlicePlot(ds, 2, "density", "c", (20, "kpc")) >>> s.hide_axes() >>> s.save()
This will save an image with no axis or colorbar.
>>> import yt >>> ds = yt.load("IsolatedGalaxy/galaxy0030/galaxy0030") >>> s = SlicePlot(ds, 2, "density", "c", (20, "kpc")) >>> s.hide_axes() >>> s.hide_colorbar() >>> s.save()
Note
By default, when removing the axes, the patch on which the axes are drawn is disabled, making it impossible to later change e.g. the background colour. To force the axes patch to be displayed while still hiding the axes, set the
draw_frame
keyword argument toTrue
.
-
hide_colorbar
(field=None)¶ Hides the colorbar for a plot and updates the size of the plot accordingly. Defaults to operating on all fields for a PlotContainer object.
- Parameters
field (string, field tuple, or list of strings or field tuples (optional)) – The name of the field(s) that we want to hide the colorbar. If None or ‘all’ is provided, will default to using all fields available for this object.
Examples
This will save an image with no colorbar.
>>> import yt >>> ds = yt.load("IsolatedGalaxy/galaxy0030/galaxy0030") >>> s = SlicePlot(ds, 2, "density", "c", (20, "kpc")) >>> s.hide_colorbar() >>> s.save()
This will save an image with no axis or colorbar.
>>> import yt >>> ds = yt.load("IsolatedGalaxy/galaxy0030/galaxy0030") >>> s = SlicePlot(ds, 2, "density", "c", (20, "kpc")) >>> s.hide_axes() >>> s.hide_colorbar() >>> s.save()
-
plot_title
= None¶
-
property
profile
¶
-
refresh
()¶
-
save
(name: Optional[str] = None, suffix: Optional[str] = None, mpl_kwargs=None)[source]¶ Saves a 2d profile plot.
- Parameters
name (str, optional) – The output file keyword.
suffix (string, optional) – Specify the image type by its suffix. If not specified, the output type will be inferred from the filename. Defaults to ‘.png’.
mpl_kwargs (dict, optional) – A dict of keyword arguments to be passed to matplotlib.
plot.save(mpl_kwargs={"bbox_inches" (>>>) –
-
set_background_color
(field, color=None)¶ set the background color to match provided color
- Parameters
field (string) – the field to set the colormap if field == ‘all’, applies to all plots.
color (string or RGBA tuple (optional)) – if set, set the background color to this color if unset, background color is set to the bottom value of the color map
-
set_cbar_minorticks
(field, state)¶ turn colorbar minor ticks “on” or “off” in the current plot, following state
- Parameters
field (string) – the field to remove colorbar minorticks
state (string) – the state indicating ‘on’ or ‘off’
-
set_cmap
(field, cmap)¶ set the colormap for one of the fields
- Parameters
field (string) – the field to set the colormap if field == ‘all’, applies to all plots.
cmap (string or tuple) – If a string, will be interpreted as name of the colormap. If a tuple, it is assumed to be of the form (name, type, number) to be used for palettable functionality. (name, type, number, bool) can be used to specify if a reverse colormap is to be used.
-
set_colorbar_label
(field, label)¶ Sets the colorbar label.
-
set_colorbar_minorticks
(field, state)¶ turn colorbar minor ticks on or off in the current plot
Displaying minor ticks reduces performance; turn them off using set_colorbar_minorticks(‘all’, False) if drawing speed is a problem.
- Parameters
field (string) – the field to remove colorbar minorticks if field == ‘all’, applies to all plots.
state (bool) – the state indicating ‘on’ (True) or ‘off’ (False)
-
set_figure_size
(size)¶ Sets a new figure size for the plot
- Parameters
size (float) – The size of the figure on the longest axis (in units of inches), including the margins but not the colorbar.
-
set_font
(font_dict=None)¶ Set the font and font properties.
- Parameters
font_dict (dict) –
A dict of keyword parameters to be passed to
matplotlib.font_manager.FontProperties
.Possible keys include:
family - The font family. Can be serif, sans-serif, cursive, ‘fantasy’ or ‘monospace’.
style - The font style. Either normal, italic or oblique.
color - A valid color string like ‘r’, ‘g’, ‘red’, ‘cobalt’, and ‘orange’.
variant - Either normal or small-caps.
size - Either a relative value of xx-small, x-small, small, medium, large, x-large, xx-large or an absolute font size, e.g. 12
stretch - A numeric value in the range 0-1000 or one of ultra-condensed, extra-condensed, condensed, semi-condensed, normal, semi-expanded, expanded, extra-expanded or ultra-expanded
weight - A numeric value in the range 0-1000 or one of ultralight, light, normal, regular, book, medium, roman, semibold, demibold, demi, bold, heavy, extra bold, or black
See the matplotlib font manager API documentation for more details. https://matplotlib.org/stable/api/font_manager_api.html
Notes
Mathtext axis labels will only obey the size and color keyword.
Examples
This sets the font to be 24-pt, blue, sans-serif, italic, and bold-face.
>>> slc = SlicePlot(ds, "x", "Density") >>> slc.set_font( ... { ... "family": "sans-serif", ... "style": "italic", ... "weight": "bold", ... "size": 24, ... "color": "blue", ... } ... )
-
set_font_size
(size)¶ Set the size of the font used in the plot
This sets the font size by calling the set_font function. See set_font for more font customization options.
- Parameters
size (float) –
absolute size of the font in points (1 pt = 1/72 inch) (The) –
-
set_log
(field, log)[source]¶ set a field to log or linear.
- Parameters
field (string) – the field to set a transform
log (boolean) – Log on/off.
-
set_minorticks
(field, state)¶ Turn minor ticks on or off in the current plot.
Displaying minor ticks reduces performance; turn them off using set_minorticks(‘all’, False) if drawing speed is a problem.
- Parameters
field (string) – the field to remove minorticks if field == ‘all’, applies to all plots.
state (bool) – the state indicating ‘on’ (True) or ‘off’ (False)
-
set_title
(field, title)[source]¶ Set a title for the plot.
Examples
>>> plot.set_title(("gas", "mass"), "This is a phase plot")
-
set_transform
(field, name)¶
-
set_unit
(field, unit)[source]¶ Sets a new unit for the requested field
- Parameters
field (string) – The name of the field that is to be changed.
unit (string or Unit object) – The name of the new unit.
-
set_xlabel
(label)¶ Allow the user to modify the X-axis title Defaults to the global value. Fontsize defaults to 18.
- Parameters
label (str) – The new string for the x-axis.
plot.set_xlabel("H2I Number Density (cm$^{-3}$)") (>>>) –
-
set_xlim
(xmin=None, xmax=None)[source]¶ Sets the limits of the x bin field
- Parameters
Examples
>>> import yt >>> ds = yt.load("IsolatedGalaxy/galaxy0030/galaxy0030") >>> pp = yt.PhasePlot(ds.all_data(), "density", "temperature", ("gas", "mass")) >>> pp.set_xlim(1e-29, 1e-24) >>> pp.save()
-
set_ylabel
(label)¶ Allow the user to modify the Y-axis title Defaults to the global value.
- Parameters
label (str) – The new string for the y-axis.
plot.set_ylabel("Temperature (K)") (>>>) –
-
set_ylim
(ymin=None, ymax=None)[source]¶ Sets the plot limits for the y bin field.
- Parameters
Examples
>>> import yt >>> ds = yt.load("IsolatedGalaxy/galaxy0030/galaxy0030") >>> pp = yt.PhasePlot( ... ds.all_data(), ... ("gas", "density"), ... ("gas", "temperature"), ... ("gas", "mass"), ... ) >>> pp.set_ylim(1e4, 1e6) >>> pp.save()
-
set_zlim
(field, zmin, zmax, dynamic_range=None)¶ set the scale of the colormap
- Parameters
field (string) – the field to set a colormap scale if field == ‘all’, applies to all plots.
zmin (float, tuple, YTQuantity or str) – the new minimum of the colormap scale. If ‘min’, will set to the minimum value in the current view.
zmax (float, tuple, YTQuantity or str) – the new maximum of the colormap scale. If ‘max’, will set to the maximum value in the current view.
- Other Parameters
dynamic_range (float (default: None)) – The dynamic range of the image. If zmin == None, will set zmin = zmax / dynamic_range If zmax == None, will set zmax = zmin * dynamic_range When dynamic_range is specified, defaults to setting zmin = zmax / dynamic_range.
-
setup_defaults
()¶
-
show
()¶ This will send any existing plots to the IPython notebook.
If yt is being run from within an IPython session, and it is able to determine this, this function will send any existing plots to the notebook for display.
If yt can’t determine if it’s inside an IPython session, it will raise YTNotInsideNotebook.
Examples
>>> from yt.mods import SlicePlot >>> slc = SlicePlot( ... ds, "x", [("gas", "density"), ("gas", "velocity_magnitude")] ... ) >>> slc.show()
-
show_axes
(field=None)¶ Shows the axes for a plot and updates the size of the plot accordingly. Defaults to operating on all fields for a PlotContainer object. See hide_axes().
- Parameters
field (string, field tuple, or list of strings or field tuples (optional)) – The name of the field(s) that we want to show the axes.
-
show_colorbar
(field=None)¶ Shows the colorbar for a plot and updates the size of the plot accordingly. Defaults to operating on all fields for a PlotContainer object. See hide_colorbar().
- Parameters
field (string, field tuple, or list of strings or field tuples (optional)) –
name of the field(s) that we want to show the colorbar. (The) –
-
x_log
= None¶
-
y_log
= None¶
-
class
yt.visualization.profile_plotter.
PhasePlotMPL
(x_data, y_data, data, x_scale, y_scale, z_scale, cmap, zlim, figure_size, fontsize, figure, axes, cax, shading='nearest')[source]¶ Bases:
yt.visualization.base_plot_types.ImagePlotMPL
A container for a single matplotlib figure and axes for a PhasePlot
-
hide_axes
(draw_frame=None)¶ Hide the axes for a plot including ticks and labels
-
hide_colorbar
()¶ Hide the colorbar for a plot including ticks and labels
-
save
(name, mpl_kwargs=None, canvas=None)¶ Choose backend and save image to disk
-
show
()¶
-
show_axes
()¶ Show the axes for a plot including ticks and labels
-
show_colorbar
()¶ Show the colorbar for a plot including ticks and labels
-
-
class
yt.visualization.profile_plotter.
PlotContainerDict
[source]¶ Bases:
collections.OrderedDict
-
clear
() → None. Remove all items from od.¶
-
copy
() → a shallow copy of od¶
-
fromkeys
(value=None)¶ Create a new ordered dictionary with keys from iterable and values set to value.
-
get
(key, default=None, /)¶ Return the value for key if key is in the dictionary, else default.
-
items
() → a set-like object providing a view on D’s items¶
-
keys
() → a set-like object providing a view on D’s keys¶
-
move_to_end
(key, last=True)¶ Move an existing element to the end (or beginning if last is false).
Raise KeyError if the element does not exist.
-
pop
(k[, d]) → v, remove specified key and return the corresponding¶ value. If key is not found, d is returned if given, otherwise KeyError is raised.
-
popitem
(last=True)¶ Remove and return a (key, value) pair from the dictionary.
Pairs are returned in LIFO order if last is true or FIFO order if false.
-
setdefault
(key, default=None)¶ Insert key with a value of default if key is not in the dictionary.
Return the value for key if key is in the dictionary, else default.
-
update
([E, ]**F) → None. Update D from dict/iterable E and F.¶ If E is present and has a .keys() method, then does: for k in E: D[k] = E[k] If E is present and lacks a .keys() method, then does: for k, v in E: D[k] = v In either case, this is followed by: for k in F: D[k] = F[k]
-
values
() → an object providing a view on D’s values¶
-
-
class
yt.visualization.profile_plotter.
ProfilePlot
(data_source, x_field, y_fields, weight_field='gas', 'mass', n_bins=64, accumulation=False, fractional=False, label=None, plot_spec=None, x_log=True, y_log=True)[source]¶ Bases:
yt.visualization.plot_container.PlotContainer
Create a 1d profile plot from a data source or from a list of profile objects.
Given a data object (all_data, region, sphere, etc.), an x field, and a y field (or fields), this will create a one-dimensional profile of the average (or total) value of the y field in bins of the x field.
This can be used to create profiles from given fields or to plot multiple profiles created from yt.data_objects.profiles.create_profile.
- Parameters
data_source (YTSelectionContainer Object) – The data object to be profiled, such as all_data, region, or sphere. If a dataset is passed in instead, an all_data data object is generated internally from the dataset.
x_field (str) – The binning field for the profile.
y_fields (str or list) – The field or fields to be profiled.
weight_field (str) – The weight field for calculating weighted averages. If None, the profile values are the sum of the field values within the bin. Otherwise, the values are a weighted average. Default : (“gas”, “mass”)
n_bins (int) – The number of bins in the profile. Default: 64.
accumulation (bool) – If True, the profile values for a bin N are the cumulative sum of all the values from bin 0 to N. Default: False.
fractional (If True the profile values are divided by the sum of all) – the profile data such that the profile represents a probability distribution function.
label (str or list of strings) – If a string, the label to be put on the line plotted. If a list, this should be a list of labels for each profile to be overplotted. Default: None.
plot_spec (dict or list of dicts) – A dictionary or list of dictionaries containing plot keyword arguments. For example, dict(color=”red”, linestyle=”:”). Default: None.
x_log (bool) – Whether the x_axis should be plotted with a logarithmic scaling (True), or linear scaling (False). Default: True.
y_log (dict or bool) – A dictionary containing field:boolean pairs, setting the logarithmic property for that field. May be overridden after instantiation using set_log A single boolean can be passed to signify all fields should use logarithmic (True) or linear scaling (False). Default: True.
Examples
This creates profiles of a single dataset.
>>> import yt >>> ds = yt.load("enzo_tiny_cosmology/DD0046/DD0046") >>> ad = ds.all_data() >>> plot = yt.ProfilePlot( ... ad, ... ("gas", "density"), ... [("gas", "temperature"), ("gas", "velocity_x")], ... weight_field=("gas", "mass"), ... plot_spec=dict(color="red", linestyle="--"), ... ) >>> plot.save()
This creates profiles from a time series object.
>>> es = yt.load_simulation("AMRCosmology.enzo", "Enzo") >>> es.get_time_series()
>>> profiles = [] >>> labels = [] >>> plot_specs = [] >>> for ds in es[-4:]: ... ad = ds.all_data() ... profiles.append( ... create_profile( ... ad, ... [("gas", "density")], ... fields=[("gas", "temperature"), ("gas", "velocity_x")], ... ) ... ) ... labels.append(ds.current_redshift) ... plot_specs.append(dict(linestyle="--", alpha=0.7))
>>> plot = yt.ProfilePlot.from_profiles( ... profiles, labels=labels, plot_specs=plot_specs ... ) >>> plot.save()
Use set_line_property to change line properties of one or all profiles.
-
annotate_text
(xpos=0.0, ypos=0.0, text=None, field='all', **text_kwargs)[source]¶ Allow the user to insert text onto the plot
The x-position and y-position must be given as well as the text string. Add text to plot at location xpos, ypos in plot coordinates for the given fields or by default for all fields. (see example below).
- Parameters
xpos (float) – Position on plot in x-coordinates.
ypos (float) – Position on plot in y-coordinates.
text (str) – The text to insert onto the plot.
field (str or tuple) – The name of the field to add text to.
**text_kwargs (dict) – Extra keyword arguments will be passed to matplotlib text instance
import yt (>>>) –
from yt.units import kpc (>>>) –
ds = yt.load("IsolatedGalaxy/galaxy0030/galaxy0030") (>>>) –
my_galaxy = ds.disk(ds.domain_center, [0.0, 0.0, 1.0], 10 * kpc, 3 * kpc) (>>>) –
plot = yt.ProfilePlot( (>>>) –
my_galaxy, ("gas", "density"), [("gas", "temperature")] (..) –
) (..) –
# Annotate text for all the fields (>>>) –
plot.annotate_text(1e-26, 1e5, "This is annotated text in the plot area.") (>>>) –
plot.save() (>>>) –
# Annotate text for a given field (>>>) –
plot.annotate_text(1e-26, 1e5, "Annotated text", ("gas", "temperature")) (>>>) –
plot.save() –
# Annotate text for multiple fields (>>>) –
fields = [("gas", "temperature"), ("gas", "density")] (>>>) –
plot.annotate_text(1e-26, 1e5, "Annotated text", fields) (>>>) –
plot.save() –
-
annotate_title
(title, field='all')[source]¶ Set a title for the plot.
- Parameters
Examples
>>> # To set title for all the fields: >>> plot.annotate_title("This is a Profile Plot")
>>> # To set title for specific fields: >>> plot.annotate_title("Profile Plot for Temperature", ("gas", "temperature"))
>>> # Setting same plot title for both the given fields >>> plot.annotate_title( ... "Profile Plot: Temperature-Dark Matter Density", ... [("gas", "temperature"), ("deposit", "dark_matter_density")], ... )
-
display
(name=None, mpl_kwargs=None)¶ Will attempt to show the plot in in an IPython notebook. Failing that, the plot will be saved to disk.
-
classmethod
from_profiles
(profiles, labels=None, plot_specs=None, y_log=None)[source]¶ Instantiate a ProfilePlot object from a list of profiles created with
create_profile()
.- Parameters
profiles (a profile or list of profiles) – A single profile or list of profile objects created with
create_profile()
.labels (list of strings) – A list of labels for each profile to be overplotted. Default: None.
plot_specs (list of dicts) – A list of dictionaries containing plot keyword arguments. For example, [dict(color=”red”, linestyle=”:”)]. Default: None.
Examples
>>> from yt import load_simulation >>> es = load_simulation("AMRCosmology.enzo", "Enzo") >>> es.get_time_series()
>>> profiles = [] >>> labels = [] >>> plot_specs = [] >>> for ds in es[-4:]: ... ad = ds.all_data() ... profiles.append( ... create_profile( ... ad, ... [("gas", "density")], ... fields=[("gas", "temperature"), ("gas", "velocity_x")], ... ) ... ) ... labels.append(ds.current_redshift) ... plot_specs.append(dict(linestyle="--", alpha=0.7)) >>> plot = ProfilePlot.from_profiles( ... profiles, labels=labels, plot_specs=plot_specs ... ) >>> plot.save()
-
get_log
(field)¶ get the transform type of a field.
- Parameters
field (string) – the field to get a transform if field == ‘all’, applies to all plots.
-
hide_axes
(field=None, draw_frame=False)¶ Hides the axes for a plot and updates the size of the plot accordingly. Defaults to operating on all fields for a PlotContainer object.
- Parameters
field (string, field tuple, or list of strings or field tuples (optional)) – The name of the field(s) that we want to hide the axes.
draw_frame (boolean) – If True, the axes frame will still be drawn. Defaults to False. See note below for more details.
Examples
This will save an image with no axes.
>>> import yt >>> ds = yt.load("IsolatedGalaxy/galaxy0030/galaxy0030") >>> s = SlicePlot(ds, 2, "density", "c", (20, "kpc")) >>> s.hide_axes() >>> s.save()
This will save an image with no axis or colorbar.
>>> import yt >>> ds = yt.load("IsolatedGalaxy/galaxy0030/galaxy0030") >>> s = SlicePlot(ds, 2, "density", "c", (20, "kpc")) >>> s.hide_axes() >>> s.hide_colorbar() >>> s.save()
Note
By default, when removing the axes, the patch on which the axes are drawn is disabled, making it impossible to later change e.g. the background colour. To force the axes patch to be displayed while still hiding the axes, set the
draw_frame
keyword argument toTrue
.
-
hide_colorbar
(field=None)¶ Hides the colorbar for a plot and updates the size of the plot accordingly. Defaults to operating on all fields for a PlotContainer object.
- Parameters
field (string, field tuple, or list of strings or field tuples (optional)) – The name of the field(s) that we want to hide the colorbar. If None or ‘all’ is provided, will default to using all fields available for this object.
Examples
This will save an image with no colorbar.
>>> import yt >>> ds = yt.load("IsolatedGalaxy/galaxy0030/galaxy0030") >>> s = SlicePlot(ds, 2, "density", "c", (20, "kpc")) >>> s.hide_colorbar() >>> s.save()
This will save an image with no axis or colorbar.
>>> import yt >>> ds = yt.load("IsolatedGalaxy/galaxy0030/galaxy0030") >>> s = SlicePlot(ds, 2, "density", "c", (20, "kpc")) >>> s.hide_axes() >>> s.hide_colorbar() >>> s.save()
-
refresh
()¶
-
save
(name: Optional[str] = None, suffix: Optional[str] = None, mpl_kwargs: Optional[Dict[str, Any]] = None)[source]¶ Saves a 1d profile plot.
- Parameters
-
set_figure_size
(size)¶ Sets a new figure size for the plot
- Parameters
size (float) – The size of the figure on the longest axis (in units of inches), including the margins but not the colorbar.
-
set_font
(font_dict=None)¶ Set the font and font properties.
- Parameters
font_dict (dict) –
A dict of keyword parameters to be passed to
matplotlib.font_manager.FontProperties
.Possible keys include:
family - The font family. Can be serif, sans-serif, cursive, ‘fantasy’ or ‘monospace’.
style - The font style. Either normal, italic or oblique.
color - A valid color string like ‘r’, ‘g’, ‘red’, ‘cobalt’, and ‘orange’.
variant - Either normal or small-caps.
size - Either a relative value of xx-small, x-small, small, medium, large, x-large, xx-large or an absolute font size, e.g. 12
stretch - A numeric value in the range 0-1000 or one of ultra-condensed, extra-condensed, condensed, semi-condensed, normal, semi-expanded, expanded, extra-expanded or ultra-expanded
weight - A numeric value in the range 0-1000 or one of ultralight, light, normal, regular, book, medium, roman, semibold, demibold, demi, bold, heavy, extra bold, or black
See the matplotlib font manager API documentation for more details. https://matplotlib.org/stable/api/font_manager_api.html
Notes
Mathtext axis labels will only obey the size and color keyword.
Examples
This sets the font to be 24-pt, blue, sans-serif, italic, and bold-face.
>>> slc = SlicePlot(ds, "x", "Density") >>> slc.set_font( ... { ... "family": "sans-serif", ... "style": "italic", ... "weight": "bold", ... "size": 24, ... "color": "blue", ... } ... )
-
set_font_size
(size)¶ Set the size of the font used in the plot
This sets the font size by calling the set_font function. See set_font for more font customization options.
- Parameters
size (float) –
absolute size of the font in points (1 pt = 1/72 inch) (The) –
-
set_line_property
(property, value, index=None)[source]¶ Set properties for one or all lines to be plotted.
- Parameters
Examples
Change all the lines in a plot plot.set_line_property(“linestyle”, “-“)
Change a single line. plot.set_line_property(“linewidth”, 4, index=0)
-
set_log
(field, log)[source]¶ set a field to log or linear.
- Parameters
field (string) – the field to set a transform
log (boolean) – Log on/off.
-
set_minorticks
(field, state)¶ Turn minor ticks on or off in the current plot.
Displaying minor ticks reduces performance; turn them off using set_minorticks(‘all’, False) if drawing speed is a problem.
- Parameters
field (string) – the field to remove minorticks if field == ‘all’, applies to all plots.
state (bool) – the state indicating ‘on’ (True) or ‘off’ (False)
-
set_transform
(field, name)¶
-
set_unit
(field, unit)[source]¶ Sets a new unit for the requested field
- Parameters
field (string) – The name of the field that is to be changed.
unit (string or Unit object) – The name of the new unit.
-
set_xlabel
(label)[source]¶ Sets a new xlabel for all profiles
- Parameters
label (string) – The label to be placed on the x-axis
-
set_xlim
(xmin=None, xmax=None)[source]¶ Sets the limits of the bin field
- Parameters
Examples
>>> import yt >>> ds = yt.load("IsolatedGalaxy/galaxy0030/galaxy0030") >>> pp = yt.ProfilePlot( ... ds.all_data(), ("gas", "density"), ("gas", "temperature") ... ) >>> pp.set_xlim(1e-29, 1e-24) >>> pp.save()
-
set_ylabel
(field, label)[source]¶ Sets a new ylabel for the specified fields
- Parameters
field (string) – The name of the field that is to be changed.
label (string) – The label to be placed on the y-axis
-
set_ylim
(field, ymin=None, ymax=None)[source]¶ Sets the plot limits for the specified field we are binning.
- Parameters
Examples
>>> import yt >>> ds = yt.load("IsolatedGalaxy/galaxy0030/galaxy0030") >>> pp = yt.ProfilePlot( ... ds.all_data(), ... ("gas", "density"), ... [("gas", "temperature"), ("gas", "velocity_x")], ... ) >>> pp.set_ylim(("gas", "temperature"), 1e4, 1e6) >>> pp.save()
-
setup_defaults
()¶
-
show
()[source]¶ This will send any existing plots to the IPython notebook.
If yt is being run from within an IPython session, and it is able to determine this, this function will send any existing plots to the notebook for display.
If yt can’t determine if it’s inside an IPython session, it will raise YTNotInsideNotebook.
Examples
>>> import yt >>> ds = yt.load("IsolatedGalaxy/galaxy0030/galaxy0030") >>> pp = ProfilePlot(ds.all_data(), ("gas", "density"), ("gas", "temperature")) >>> pp.show()
-
show_axes
(field=None)¶ Shows the axes for a plot and updates the size of the plot accordingly. Defaults to operating on all fields for a PlotContainer object. See hide_axes().
- Parameters
field (string, field tuple, or list of strings or field tuples (optional)) – The name of the field(s) that we want to show the axes.
-
show_colorbar
(field=None)¶ Shows the colorbar for a plot and updates the size of the plot accordingly. Defaults to operating on all fields for a PlotContainer object. See hide_colorbar().
- Parameters
field (string, field tuple, or list of strings or field tuples (optional)) –
name of the field(s) that we want to show the colorbar. (The) –
-
x_log
= None¶
-
x_title
= None¶
-
y_log
= None¶
-
y_title
= None¶