pymatgen.util.plotting module

add_fig_kwargs(func)[source]

Decorator that adds keyword arguments for functions returning matplotlib figures.

The function should return either a matplotlib figure or None to signal some sort of error/unexpected event. See doc string below for the list of supported options.

get_ax3d_fig_plt(ax=None)[source]

Helper function used in plot functions supporting an optional Axes3D argument. If ax is None, we build the matplotlib figure and create the Axes3D else we return the current active figure.

Returns:Axes object figure: matplotlib figure plt: matplotlib pyplot module.
Return type:ax
get_ax_fig_plt(ax=None)[source]

Helper function used in plot functions supporting an optional Axes argument. If ax is None, we build the matplotlib figure and create the Axes else we return the current active figure.

Returns:Axes object figure: matplotlib figure plt: matplotlib pyplot module.
Return type:ax
get_axarray_fig_plt(ax_array, nrows=1, ncols=1, sharex=False, sharey=False, squeeze=True, subplot_kw=None, gridspec_kw=None, **fig_kw)[source]

Helper function used in plot functions that accept an optional array of Axes as argument. If ax_array is None, we build the matplotlib figure and create the array of Axes by calling plt.subplots else we return the current active figure.

Returns:Array of Axes objects figure: matplotlib figure plt: matplotlib pyplot module.
Return type:ax
pretty_plot(width=8, height=None, plt=None, dpi=None, color_cycle=('qualitative', 'Set1_9'))[source]

Provides a publication quality plot, with nice defaults for font sizes etc.

Parameters:
  • width (float) – Width of plot in inches. Defaults to 8in.
  • height (float) – Height of plot in inches. Defaults to width * golden ratio.
  • plt (matplotlib.pyplot) – If plt is supplied, changes will be made to an existing plot. Otherwise, a new plot will be created.
  • dpi (int) – Sets dot per inch for figure. Defaults to 300.
  • color_cycle (tuple) – Set the color cycle for new plots to one of the color sets in palettable. Defaults to a qualitative Set1_9.
Returns:

Matplotlib plot object with properly sized fonts.

pretty_plot_two_axis(x, y1, y2, xlabel=None, y1label=None, y2label=None, width=8, height=None, dpi=300)[source]

Variant of pretty_plot that does a dual axis plot. Adapted from matplotlib examples. Makes it easier to create plots with different axes.

Parameters:
  • x (np.ndarray/list) – Data for x-axis.
  • y1 (dict/np.ndarray/list) – Data for y1 axis (left). If a dict, it will be interpreted as a {label: sequence}.
  • y2 (dict/np.ndarray/list) – Data for y2 axis (right). If a dict, it will be interpreted as a {label: sequence}.
  • xlabel (str) – If not None, this will be the label for the x-axis.
  • y1label (str) – If not None, this will be the label for the y1-axis.
  • y2label (str) – If not None, this will be the label for the y2-axis.
  • width (float) – Width of plot in inches. Defaults to 8in.
  • height (float) – Height of plot in inches. Defaults to width * golden ratio.
  • dpi (int) – Sets dot per inch for figure. Defaults to 300.
Returns:

matplotlib.pyplot

pretty_polyfit_plot(x, y, deg=1, xlabel=None, ylabel=None, **kwargs)[source]

Convenience method to plot data with trend lines based on polynomial fit.

Parameters:
  • x – Sequence of x data.
  • y – Sequence of y data.
  • deg (int) – Degree of polynomial. Defaults to 1.
  • xlabel (str) – Label for x-axis.
  • ylabel (str) – Label for y-axis.
  • **kwargs – Keyword args passed to pretty_plot.
Returns:

matplotlib.pyplot object.