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.

format_formula(formula)[source]

Converts str of chemical formula into latex format for labelling purposes

Parameters

formula (str) – Chemical formula

get_ax3d_fig_plt(ax=None, **kwargs)[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.

Parameters

kwargs – keyword arguments are passed to plt.figure if ax is not None.

Returns

Axes object figure: matplotlib figure plt: matplotlib pyplot module.

Return type

ax

get_ax_fig_plt(ax=None, **kwargs)[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.

Parameters

kwargs – keyword arguments are passed to plt.figure if ax is not None.

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

periodic_table_heatmap(elemental_data, cbar_label='', show_plot=False, cmap='YlOrRd', blank_color='grey', value_format=None, max_row=9)[source]

A static method that generates a heat map overlapped on a periodic table.

Parameters
  • elemental_data (dict) – A dictionary with the element as a key and a value assigned to it, e.g. surface energy and frequency, etc. Elements missing in the elemental_data will be grey by default in the final table elemental_data={“Fe”: 4.2, “O”: 5.0}.

  • cbar_label (string) – Label of the colorbar. Default is “”.

  • figure_name (string) – Name of the plot (absolute path) being saved if not None.

  • show_plot (bool) – Whether to show the heatmap. Default is False.

  • value_format (str) – Formatting string to show values. If None, no value is shown. Example: “%.4f” shows float to four decimals.

  • cmap (string) – Color scheme of the heatmap. Default is ‘coolwarm’.

  • blank_color (string) – Color assigned for the missing elements in elemental_data. Default is “grey”.

  • max_row (integer) – Maximum number of rows of the periodic table to be shown. Default is 9, which means the periodic table heat map covers the first 9 rows of elements.

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.

van_arkel_triangle(list_of_materials, annotate=True)[source]
A static method that generates a binary van Arkel-Ketelaar triangle to

quantify the ionic, metallic and covalent character of a compound by plotting the electronegativity difference (y) vs average (x). See:

A.E. van Arkel, Molecules and Crystals in Inorganic Chemistry,

Interscience, New York (1956)

and
J.A.A Ketelaar, Chemical Constitution (2nd edn.), An Introduction

to the Theory of the Chemical Bond, Elsevier, New York (1958)

Parameters
  • list_of_materials (list) – A list of computed entries of binary materials or a list of lists containing two elements (str).

  • annotate (bool) – Whether or not to lable the points on the triangle with reduced formula (if list of entries) or pair of elements (if list of list of str).