diff --git a/solventmapcreator/polynomialanalysis/polynomialanalysisplotting.py b/solventmapcreator/polynomialanalysis/polynomialanalysisplotting.py new file mode 100644 index 0000000000000000000000000000000000000000..6fb40c98ec060646adebf6d7632cfcd621a7faf0 --- /dev/null +++ b/solventmapcreator/polynomialanalysis/polynomialanalysisplotting.py @@ -0,0 +1,56 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- +""" +Script for plotting the polynomial data analysis information as bar charts. + +@author: mark +""" + +import logging +import numpy as np +import matplotlib.pyplot as plt +import resultsanalysis.resultsoutput.plottinginput as plottinginput + +logging.basicConfig() +LOGGER = logging.getLogger(__name__) +LOGGER.setLevel(logging.WARN) + +COLOUR_LIST = ["r", "b", "g", "c", "m", "y"] + +def create_bar_plot_write_to_file(input_data, filename_stem, **kwargs): + """This creates the bar plot and saves it to file. + """ + bar_plot, bar_plot_axis = create_bar_plot(input_data, **kwargs) + fileformat = kwargs.get("fileformat", "eps") + output_filename = filename_stem + fileformat + plt.savefig(output_filename, format=fileformat) + plt.close(bar_plot) + +def create_bar_plot(input_data, **kwargs): + """This creates the bar plot. + """ + bar_plot, bar_plot_axis = create_plot_with_axis(kwargs.get("figsize",plottinginput.FIGURE_SIZES['vertical bar chart'])) + index = np.arange(len(input_data[0])) + n_values = input_data[1] + for i in range(len(n_values)): + if i == 0: + bar_plot_axis.bar(index, n_values[i], color=COLOUR_LIST[i]) + else: + bottom = np.zeros(len(index)) + for j in range(i-1): + bottom += np.array(n_values[j]) + bar_plot_axis.bar(index, n_values[i], bottom=bottom, color=COLOUR_LIST[i]) + add_labels_to_plot(bar_plot_axis, index, input_data[0]) + return bar_plot, bar_plot_axis + +def add_labels_to_plot(bar_plot_axis, index, order_tuple): + """This adds the labels to the given axis. + """ + bar_plot_axis.ylabel("N") + bar_plot_axis.xlabel("polynomial order") + bar_plot_axis.xticks(index, order_tuple) + +def create_plot_with_axis(figsize): + """This creates the plot and axis. + """ + return plottinginput.create_plot_with_axis(figsize)