ai4materials.utils.utils_plotting module

ai4materials.utils.utils_plotting.aggregate_struct_trans_data(filename, nb_rows_to_cut=0, nb_samples=None, nb_order_param_steps=None, min_order_param=0.0, max_order_param=None, prob_idxs=None, with_uncertainty=True, uncertainty_types=('variation_ratio', 'predictive_entropy', 'mutual_information'))[source]

Aggregate structural transition data in order to plot it later.

Starting from the results_file of the run_cnn_model function, aggregate the data by a given order parameter and the probabilities of each class. This is used to prepare the data for the structural transition plots, as shown in Fig. 4, Ziletti et al., Nature Communications 9, 2775 (2018).

Parameters:

filename: string,
Full path to the results_file created by the run_cnn_model function. This is a csv file
nb_samples: int
Number of samples present in results_file for each order parameter step.
nb_order_param_steps: int
Number of order parameter steps. For example, if we are interpolating between structure_1 and structure_2 with 10 steps, nb_order_param_steps=10.
max_order_param: float
Maximum number that the order parameter will take in the dataset. This is used to create (together with nb_order_param_steps) to create the linear space which will be later used by the plotting function.
prob_idxs: list of int
List of integers which correspond to the classes for which the probabilities will be extracted from the results_file. prob_idxs=[0, 3] will extract only prob_predictions_0 and prob_predictions_3 from the results_file.

Returns:

panda dataframe

A panda dataframe with the following columns:

  • a_to_b_index_ : value of the order parameter
  • 2i columns (where the i’s are the elements of the list prob_idxs)

as below:

prob_predictions_i_mean : mean of the distribution of classification probability i for the given a_to_b_index_ value of the order parameter.

prob_predictions_i_std : standard deviation of the distribution of classification probability i for the given a_to_b_index_ value of the order parameter.

  • [optional]: columns containing uncertainty quantification

Code author: Angelo Ziletti <angelo.ziletti@gmail.com>

ai4materials.utils.utils_plotting.insert_newlines(string, every=64)[source]
ai4materials.utils.utils_plotting.make_crossover_plot(df_results, filename, filename_suffix, title, labels, nb_order_param_steps, plot_type='probability', prob_idxs=None, uncertainty_type='mutual_information', linewidth=1.0, markersize=1.0, max_nb_ticks=None, palette=None, show_plot=False, style='publication', x_label='Order parameter')[source]

Starting from an aggregated data panda dataframe, plot classification probability distributions as a function of an order parameter.

This will produce a plot along the lines of Fig. 4, Ziletti et al.

Parameters:

df_results: panda dataframe,
Panda dataframe returned by the aggregate_struct_trans_data function.
filename: string
Full path to the results_file created by the run_cnn_model function. This is a csv file. Only used to name the generated plot appriately.
filename_suffix: string
Suffix to be put for the plot filename. This suffix will determine the format of the output plot (e.g. ‘.png’ or ‘.svg’ will create a png or an svg file, respectively.)
title: string
Title of the plot
plot_type: str (options: ‘probability’, ‘uncertainty’)
Plot either probabilities of classification or uncertainty.
uncertainty_type: str (options: ‘mutual_information’, ‘predictive_entropy’)
Type of uncertainty estimation to be plotted. Used only if `plot_type`=’uncertainty’.
prob_idxs: list of int
List of integers which correspond to the classes for which the probabilities will be extracted from the results_file. prob_idxs=[0, 3] will extract only prob_predictions_0 and prob_predictions_3 from the results_file. They should correspond (or be a subset) of the prob_idxs specified in aggregate_struct_trans_data.
nb_order_param_steps: int
Number of order parameter steps. For example, if we are interpolating between structure_1 and structure_2 with 10 steps, nb_order_param_steps=10. Must be the same as specified in aggregate_struct_trans_data. Different values might work, but could give rise to unexpected behaviour.
show_plot: bool, optional, default: False
If True, it opens the generated plot.
style: string, optional, {‘publication’}
If style==’publication’, load the default matplotlib style (white background). Otherwise, use the ‘fivethirtyeight’ matplotlib style (black background). plt.style.use(‘fivethirtyeight’)
x_label: string, optional, default: “Order parameter”
Label for the x-axis (the order parameter axis)

Code author: Angelo Ziletti <angelo.ziletti@gmail.com>

ai4materials.utils.utils_plotting.make_multiple_image_plot(data, title='Figure 1', cmap=<matplotlib.colors.LinearSegmentedColormap object>, n_rows=None, n_cols=None, vmin=None, vmax=None, filename=None, save=False)[source]
ai4materials.utils.utils_plotting.make_plot_accuracy(step, train_data, val_data)[source]
ai4materials.utils.utils_plotting.make_plot_cross_entropy_loss(step, train_data, val_data, title=None)[source]
ai4materials.utils.utils_plotting.plot_confusion_matrix(conf_matrix, classes, conf_matrix_file, normalize=False, title='Confusion matrix', title_true_label='True label', title_pred_label='Predicted label', cmap='Blues')[source]

This function prints and plots the confusion matrix. Normalization can be applied by setting normalize=True.

ai4materials.utils.utils_plotting.plot_save_cnn_results(filename, accuracy=True, cross_entropy_loss=True, show_plot=False)[source]
Plot and save results of a convolutional neural network calculation
from the .csv file written by Keras CSVLogger.

Code author: Angelo Ziletti <angelo.ziletti@gmail.com>

ai4materials.utils.utils_plotting.plot_sph_harmonics()[source]
ai4materials.utils.utils_plotting.rgb_colormaps(color)[source]

Obtain colormaps for RGB.

For a general overview: https://matplotlib.org/examples/pylab_examples/custom_cmap.html

ai4materials.utils.utils_plotting.show_images(images, filename_png, cols=1, titles=None)[source]

Display a list of images in a single figure with matplotlib.

Taken from https://stackoverflow.com/questions/11159436/multiple-figures-in-a-single-window

Parameters:

images: list of np.arrays
Images to be plotted. It must be compatible with plt.imshow.
cols: int, optional, (default = 1)
Number of columns in figure (number of rows is set to np.ceil(n_images/float(cols))).
titles: list of strings
List of titles corresponding to each image.