yt.visualization.profile_plotter module

This is a simple mechanism for interfacing with Profile and Phase plots

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(S[, v]) → New ordered dictionary with keys from S.

If not specified, the value defaults to None.

get(k[, d]) → D[k] if k in D, else d. d defaults to None.
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==False).

Raises KeyError if the element does not exist. When last=True, acts like a fast version of self[key]=self.pop(key).

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() → (k, v), return and remove a (key, value) pair.

Pairs are returned in LIFO order if last is true or FIFO order if false.

setdefault(k[, d]) → od.get(k,d), also set od[k]=d if k not in od
update([E, ]**F) → None. Update D from mapping/iterable E and F.

If E present and has a .keys() method, does: for k in E: D[k] = E[k] If E present and lacks .keys() method, does: for (k, v) in E: D[k] = v In either case, this is followed by: for k, v in F.items(): D[k] = v

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(S[, v]) → New ordered dictionary with keys from S.

If not specified, the value defaults to None.

get(k[, d]) → D[k] if k in D, else d. d defaults to None.
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==False).

Raises KeyError if the element does not exist. When last=True, acts like a fast version of self[key]=self.pop(key).

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() → (k, v), return and remove a (key, value) pair.

Pairs are returned in LIFO order if last is true or FIFO order if false.

setdefault(k[, d]) → od.get(k,d), also set od[k]=d if k not in od
update([E, ]**F) → None. Update D from mapping/iterable E and F.

If E present and has a .keys() method, does: for k in E: D[k] = E[k] If E present and lacks .keys() method, does: for (k, v) in E: D[k] = v In either case, this is followed by: for k, v in F.items(): D[k] = v

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='cell_mass', x_bins=128, y_bins=128, accumulation=False, fractional=False, fontsize=18, figure_size=8.0)[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.
  • 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 : “cell_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)

Examples

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

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

Parameters:
  • field (str or tuple) – The name of the field to add text to.
  • xpos (float) – Position on plot in x-coordinates.
  • ypos (float) – Position on plot in y-coordinates.
  • text (str) – The text to insert onto the plot.
  • text_kwargs (dict) – Dictionary of text keyword arguments to be passed to matplotlib
  • plot.annotate_text(1e-15, 5e4, "Hello YT") (>>>) –
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.

classmethod from_profile(profile, fontsize=18, figure_size=8.0)[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.

Examples

>>> import yt
>>> ds = yt.load('IsolatedGalaxy/galaxy0030/galaxy0030')
>>> extrema = {
... 'density': (1e-31, 1e-24),
... 'temperature': (1e1, 1e8),
... 'cell_mass': (1e-6, 1e-1),
... }
>>> profile = yt.create_profile(ds.all_data(), ['density', 'temperature'],
...                             fields=['cell_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
plot_title = None
profile
refresh()
reset_plot()[source]
save(name=None, suffix=None, mpl_kwargs=None)[source]

Saves a 2d profile plot.

Parameters:
  • name (str) – The output file keyword.
  • suffix (string) – Specify the image type by its suffix. If not specified, the output type will be inferred from the filename. Defaults to PNG.
  • mpl_kwargs (dict) – A dict of keyword arguments to be passed to matplotlib.
  • 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

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

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.

Parameters:
  • field (str or tuple) – The name of the field to modify the label for.
  • label (str) – The new label
  • plot.set_colorbar_label("density", "Dark Matter Density (g cm$^{-3}$)") (>>>) –
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)[source]

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. http://matplotlib.org/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.

>>> prof = ProfilePlot(ds.all_data(), 'density', 'temperature')
>>> 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’, ‘off’) if drawing speed is a problem.

Parameters:
  • field (string) – the field to remove minorticks
  • state (string) – the state indicating ‘on’ or ‘off’
set_title(field, title)[source]

Set a title for the plot.

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

Examples

>>> plot.set_title("cell_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.
  • new_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:
  • x_title (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:
  • xmin (float or None) – The new x minimum in the current x-axis units. Defaults to None, which leaves the xmin unchanged.
  • xmax (float or None) – The new x maximum in the current x-axis units. Defaults to None, which leaves the xmax unchanged.

Examples

>>> import yt
>>> ds = yt.load('IsolatedGalaxy/galaxy0030/galaxy0030')
>>> pp = yt.PhasePlot(ds.all_data(), 'density', 'temperature', 'cell_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:
  • ymin (float or None) – The new y minimum in the current y-axis units. Defaults to None, which leaves the ymin unchanged.
  • ymax (float or None) – The new y maximum in the current y-axis units. Defaults to None, which leaves the ymax unchanged.

Examples

>>> import yt
>>> ds = yt.load('IsolatedGalaxy/galaxy0030/galaxy0030')
>>> pp = yt.PhasePlot(ds.all_data(), 'density', 'temperature', 'cell_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) – the new minimum of the colormap scale. If ‘min’, will set to the minimum value in the current view.
  • zmax (float) – 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.

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", ["Density", "VelocityMagnitude"])
>>> slc.show()
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)[source]

Bases: yt.visualization.base_plot_types.ImagePlotMPL

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

hide_axes()

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(*args, **kwds)[source]

Bases: collections.OrderedDict

clear() → None. Remove all items from od.
copy() → a shallow copy of od
fromkeys(S[, v]) → New ordered dictionary with keys from S.

If not specified, the value defaults to None.

get(k[, d]) → D[k] if k in D, else d. d defaults to None.
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==False).

Raises KeyError if the element does not exist. When last=True, acts like a fast version of self[key]=self.pop(key).

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() → (k, v), return and remove a (key, value) pair.

Pairs are returned in LIFO order if last is true or FIFO order if false.

setdefault(k[, d]) → od.get(k,d), also set od[k]=d if k not in od
update([E, ]**F) → None. Update D from mapping/iterable E and F.

If E present and has a .keys() method, does: for k in E: D[k] = E[k] If E present and lacks .keys() method, does: for (k, v) in E: D[k] = v In either case, this is followed by: for k, v in F.items(): D[k] = v

values() → an object providing a view on D's values
class yt.visualization.profile_plotter.ProfilePlot(data_source, x_field, y_fields, weight_field='cell_mass', n_bins=64, accumulation=False, fractional=False, label=None, plot_spec=None, x_log=None, y_log=None)[source]

Bases: object

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.
  • 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 : “cell_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) – If not None, whether the x_axis should be plotted with a logarithmic scaling. Default: None
  • y_log (dict) – A dictionary containing field:boolean pairs, setting the logarithmic property for that field. May be overridden after instantiation using set_log. Default: None

Examples

This creates profiles of a single dataset.

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

This creates profiles from a time series object.

>>> es = yt.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, ["density"],
...                                    fields=["temperature",
...                                            "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()

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

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 simulation
>>> es = 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, ["Density"],
...                                    fields=["Temperature",
...                                            "x-velocity"]))
...     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()
save(name=None, suffix=None, mpl_kwargs=None)[source]

Saves a 1d profile plot.

Parameters:
  • name (str) – The output file keyword.
  • suffix (string) – Specify the image type by its suffix. If not specified, the output type will be inferred from the filename. Defaults to PNG.
  • mpl_kwargs (dict) – A dict of keyword arguments to be passed to matplotlib.
set_line_property(property, value, index=None)[source]

Set properties for one or all lines to be plotted.

Parameters:
  • property (str) – The line property to be set.
  • value (str, int, float) – The value to set for the line property.
  • index (int) – The index of the profile in the list of profiles to be changed. If None, change all plotted lines. Default : None.

Examples

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

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

set_log(field, log)[source]

set a field to log or linear.

Parameters:
  • field (string) – the field to set a transform
  • log (boolean) – Log on/off.
set_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.
  • new_unit (string or Unit object) – The name of the new unit.
set_xlim(xmin=None, xmax=None)[source]

Sets the limits of the bin field

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

Examples

>>> import yt
>>> ds = yt.load('IsolatedGalaxy/galaxy0030/galaxy0030')
>>> pp = yt.ProfilePlot(ds.all_data(), 'density', 'temperature')
>>> pp.set_xlim(1e-29, 1e-24)
>>> pp.save()
set_ylim(field, ymin=None, ymax=None)[source]

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

Parameters:
  • field (string or field tuple) –
  • field that we want to adjust the plot limits for. (The) –
  • ymin (float or None) – The new y minimum. Defaults to None, which leaves the ymin unchanged.
  • ymax (float or None) – The new y maximum. Defaults to None, which leaves the ymax unchanged.

Examples

>>> import yt
>>> ds = yt.load('IsolatedGalaxy/galaxy0030/galaxy0030')
>>> pp = yt.ProfilePlot(ds.all_data(), 'density', ['temperature', 'x-velocity'])
>>> pp.set_ylim('temperature', 1e4, 1e6)
>>> pp.save()
show()[source]

This will send any existing plots to the IPython notebook.

If yt is being run from within an IPython session, and it is able to determine this, this function will send any existing plots to the notebook for display.

If yt can’t determine if it’s inside an IPython session, it will raise YTNotInsideNotebook.

Examples

>>> import yt
>>> ds = yt.load('IsolatedGalaxy/galaxy0030/galaxy0030')
>>> pp = ProfilePlot(ds.all_data(), 'density', 'temperature')
>>> pp.show()
x_log = None
x_title = None
y_log = None
y_title = None
yt.visualization.profile_plotter.get_canvas(name)[source]
yt.visualization.profile_plotter.invalidate_profile(f)[source]
yt.visualization.profile_plotter.sanitize_label(label, nprofiles)[source]