yt.visualization.line_plot module

A mechanism for plotting field values along a line through a dataset

class yt.visualization.line_plot.LineBuffer(ds, start_point, end_point, npoints, label = None)[source]

Bases: object

This takes a data source and implements a protocol for generating a ‘pixelized’, fixed-resolution line buffer. In other words, LineBuffer takes a starting point, ending point, and number of sampling points and can subsequently generate YTArrays of field values along the sample points.

Parameters:
  • ds (yt.data_objects.static_output.Dataset) – This is the dataset object holding the data that can be sampled by the LineBuffer
  • start_point (n-element list, tuple, ndarray, or YTArray) – Contains the coordinates of the first point for constructing the LineBuffer. Must contain n elements where n is the dimensionality of the dataset.
  • end_point (n-element list, tuple, ndarray, or YTArray) – Contains the coordinates of the first point for constructing the LineBuffer. Must contain n elements where n is the dimensionality of the dataset.
  • npoints (int) – How many points to sample between start_point and end_point

Examples

>>> lb = yt.LineBuffer(ds, (.25, 0, 0), (.25, 1, 0), 100)
>>> lb[('all', 'u')].max()
0.11562424257143075 dimensionless
keys()[source]
class yt.visualization.line_plot.LinePlot(ds, fields, start_point, end_point, npoints, figure_size=5.0, fontsize=14.0, field_labels=None)[source]

Bases: yt.visualization.plot_container.PlotContainer

A class for constructing line plots

Parameters:
  • ds (yt.data_objects.static_output.Dataset) – This is the dataset object corresponding to the simulation output to be plotted.
  • fields (string / tuple, or list of strings / tuples) – The name(s) of the field(s) to be plotted.
  • start_point (n-element list, tuple, ndarray, or YTArray) – Contains the coordinates of the first point for constructing the line. Must contain n elements where n is the dimensionality of the dataset.
  • end_point (n-element list, tuple, ndarray, or YTArray) – Contains the coordinates of the first point for constructing the line. Must contain n elements where n is the dimensionality of the dataset.
  • npoints (int) – How many points to sample between start_point and end_point for constructing the line plot
  • figure_size (int or two-element iterable of ints) – Size in inches of the image. Default: 5 (5x5)
  • fontsize (int) – Font size for all text in the plot. Default: 14
  • field_labels (dictionary) – Keys should be the field names. Values should be latex-formattable strings used in the LinePlot legend Default: None

Example

>>> import yt
>>>
>>> ds = yt.load('IsolatedGalaxy/galaxy0030/galaxy0030')
>>>
>>> plot = yt.LinePlot(ds, 'density', [0, 0, 0], [1, 1, 1], 512)
>>> plot.add_legend('density')
>>> plot.set_x_unit('cm')
>>> plot.set_unit('density', 'kg/cm**3')
>>> plot.save()
annotate_legend(field)[source]

Adds a legend to the LinePlot instance. The _sanitize_dimensions call ensures that a legend label will be added for every field of a multi-field plot

annotate_title(field, title)[source]

Set the unit used to plot the field

Parameters:
  • field (str or field tuple) – The name of the field to set the units for
  • title (str) – The title to use for the 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_lines(ds, fields, lines, figure_size=5.0, font_size=14.0, field_labels=None)[source]

A class method for constructing a line plot from multiple sampling lines

Parameters:
  • ds (yt.data_objects.static_output.Dataset) – This is the dataset object corresponding to the simulation output to be plotted.
  • fields (field name or list of field names) – The name(s) of the field(s) to be plotted.
  • lines (list of yt.visualization.line_plot.LineBuffer instances) – The lines from which to sample data
  • figure_size (int or two-element iterable of ints) – Size in inches of the image. Default: 5 (5x5)
  • fontsize (int) – Font size for all text in the plot. Default: 14
  • field_labels (dictionary) – Keys should be the field names. Values should be latex-formattable strings used in the LinePlot legend Default: None

Example

>>> ds = yt.load('SecondOrderTris/RZ_p_no_parts_do_nothing_bcs_cone_out.e', step=-1)
>>> fields = [field for field in ds.field_list if field[0] == 'all']
>>> lines = []
>>> lines.append(yt.LineBuffer(ds, [0.25, 0, 0], [0.25, 1, 0], 100, label='x = 0.25'))
>>> lines.append(yt.LineBuffer(ds, [0.5, 0, 0], [0.5, 1, 0], 100, label='x = 0.5'))
>>> plot = yt.LinePlot.from_lines(ds, fields, lines)
>>> plot.save()
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 or tuple) – The base of the filename. If name is a directory or if name is not set, the filename of the dataset is used. For a tuple, the resulting path will be given by joining the elements of the tuple
  • 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)

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_unit(field, unit_name)[source]

Set the unit used to plot the field

Parameters:
  • field (str or field tuple) – The name of the field to set the units for
  • unit_name (str) – The name of the unit to use for this field
set_x_unit(unit_name)[source]

Set the unit to use along the x-axis

Parameters:unit_name (str) – The name of the unit to use for the x-axis 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_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)") (>>>) –
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.line_plot.LinePlotDictionary(data_source)[source]

Bases: yt.visualization.plot_container.PlotDictionary

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