yt.visualization.plot_container module

A base class for “image” plots with colorbars.

class yt.visualization.plot_container.FieldTransform(name, func, locator)[source]

Bases: object

ticks(mi, ma)[source]
class yt.visualization.plot_container.ImagePlotContainer(data_source, figure_size, fontsize)[source]

Bases: yt.visualization.plot_container.PlotContainer

A container for plots with colorbars.

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.

get_log(field)

get the transform type of a field.

Parameters:field (string) – the field to get a transform
refresh()
save(name=None, suffix=None, mpl_kwargs=None)

saves the plot to disk.

Parameters:
  • name (string) – The base of the filename. If name is a directory or if name is not set, the filename of the dataset is used.
  • suffix (string) – Specify the image type by its suffix. If not specified, the output type will be inferred from the filename. Defaults to PNG.
  • mpl_kwargs (dict) – A dict of keyword arguments to be passed to matplotlib.
  • slc.save(mpl_kwargs={'bbox_inches' (>>>) –
set_background_color(field, color=None)[source]

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

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

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

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)

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.

>>> slc = SlicePlot(ds, 'x', 'Density')
>>> slc.set_font({'family':'sans-serif', 'style':'italic',
...               'weight':'bold', 'size':24, 'color':'blue'})
set_font_size(size)

Set the size of the font used in the plot

This sets the font size by calling the set_font function. See set_font for more font customization options.

Parameters:
  • size (float) –
  • absolute size of the font in points (1 pt = 1/72 inch) (The) –
set_log(field, log, linthresh=None)

set a field to log or linear.

Parameters:
  • field (string) – the field to set a transform
  • log (boolean) – Log on/off.
  • linthresh (float (must be positive)) – linthresh will be enabled for symlog scale only when log is true
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_transform(field, name)
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_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_zlim(field, zmin, zmax, dynamic_range=None)[source]

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()
class yt.visualization.plot_container.PlotContainer(data_source, figure_size, fontsize)[source]

Bases: object

A container for generic plots

display(name=None, mpl_kwargs=None)[source]

Will attempt to show the plot in in an IPython notebook. Failing that, the plot will be saved to disk.

get_log(field)[source]

get the transform type of a field.

Parameters:field (string) – the field to get a transform
refresh()[source]
save(name=None, suffix=None, mpl_kwargs=None)[source]

saves the plot to disk.

Parameters:
  • name (string) – The base of the filename. If name is a directory or if name is not set, the filename of the dataset is used.
  • suffix (string) – Specify the image type by its suffix. If not specified, the output type will be inferred from the filename. Defaults to PNG.
  • mpl_kwargs (dict) – A dict of keyword arguments to be passed to matplotlib.
  • slc.save(mpl_kwargs={'bbox_inches' (>>>) –
set_figure_size(size)[source]

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.

>>> slc = SlicePlot(ds, 'x', 'Density')
>>> slc.set_font({'family':'sans-serif', 'style':'italic',
...               'weight':'bold', 'size':24, 'color':'blue'})
set_font_size(size)[source]

Set the size of the font used in the plot

This sets the font size by calling the set_font function. See set_font for more font customization options.

Parameters:
  • size (float) –
  • absolute size of the font in points (1 pt = 1/72 inch) (The) –
set_log(field, log, linthresh=None)[source]

set a field to log or linear.

Parameters:
  • field (string) – the field to set a transform
  • log (boolean) – Log on/off.
  • linthresh (float (must be positive)) – linthresh will be enabled for symlog scale only when log is true
set_minorticks(field, state)[source]

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_transform(field, name)[source]
set_xlabel(label)[source]

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

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

>>> from yt.mods import SlicePlot
>>> slc = SlicePlot(ds, "x", ["Density", "VelocityMagnitude"])
>>> slc.show()
class yt.visualization.plot_container.PlotDictionary(data_source, default_factory=None)[source]

Bases: collections.defaultdict

clear() → None. Remove all items from D.
copy() → a shallow copy of D.
default_factory

Factory for default value called by __missing__().

fromkeys()

Returns a new dict with keys from iterable and values equal to value.

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
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), remove and return some (key, value) pair as a

2-tuple; but raise KeyError if D is empty.

setdefault(k[, d]) → D.get(k,d), also set D[k]=d if k not in D
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
yt.visualization.plot_container.apply_callback(f)[source]
yt.visualization.plot_container.get_log_minorticks(vmin, vmax)[source]

calculate positions of linear minorticks on a log colorbar

Parameters:
  • vmin (float) – the minimum value in the colorbar
  • vmax (float) – the maximum value in the colorbar
yt.visualization.plot_container.get_symlog_minorticks(linthresh, vmin, vmax)[source]

calculate positions of linear minorticks on a symmetric log colorbar

Parameters:
  • linthresh (float) – the threshold for the linear region
  • vmin (float) – the minimum value in the colorbar
  • vmax (float) – the maximum value in the colorbar
yt.visualization.plot_container.invalidate_data(f)[source]
yt.visualization.plot_container.invalidate_figure(f)[source]
yt.visualization.plot_container.invalidate_plot(f)[source]
yt.visualization.plot_container.validate_plot(f)[source]