def scatter(self, column_name_draw, column_name_true_values=None, separators_plot=None, palette='PuOr', hue=None, style=None, markers=None, sizes=None, dict_plot_for_main_line={}, path_save_plot=None, *args, **kwargs): # TODO 27/06/2021 nie_k: add the ax parameter as it is in line plot. """ Semantics: Draw the scatterplot. Issue with seaborn: When writing overloading, always draw before using super(). Otherwise, the legend is not actualised. If it is, then seaborn's style in the legend will be erased. Args: column_name_draw (str): The column of the dataframe used to retrieve the data to draw column_name_true_values (str): The column where true values are present separators_plot (list of str): List of columns to group by, this will generate a plot for the product of unique elements in each column palette (colors of seaborn): colors for hue. Some example in priv_lib_plot/acolor/colors_seaborn.py hue (str): The column used in order to draw multiple lines on the same plot for the data, discriminating by this column style (str): separator for marker style markers (bool): sizes: dict_plot_for_main_line (dict): additional parameters for the plot (evolution line). path_save_plot (str): Path to specify where the plot should be saved. Not saved if is None. Returns: Dependency: todo write the dependency """ # super call for gathering all separators together and having the group by done. separators_plot, global_dict, keys = super().draw( separators_plot=separators_plot, *args, **kwargs) self._raise_if_separator_is_evolution( separators_plot) # test evolution_name is not part of separators. plots = [] for key in keys: if key is None: # case where we cannot use groupby. data = global_dict separators_plot = ["data used"] # for title key = ["whole dataset"] # for title else: data = global_dict.get_group(key) # creation of the plot plot = APlot() plots.append(plot) sns.scatterplot(x=self.EVOLUTION_COLUMN, y=column_name_draw, hue=hue, style=style, sizes=sizes, markers=markers, legend='full', palette=palette, data=data, ax=plot._axs[0], **dict_plot_for_main_line) if column_name_true_values is not None: sns.lineplot(x=self.EVOLUTION_COLUMN, y=column_name_true_values, hue=hue, legend=False, palette=palette, data=data, ax=plot._axs[0], color='r', linestyle='--', linewidth=0.5, label='true value', **dict_plot_for_main_line) fig_dict = self.get_dict_fig(separators_plot, key, **kwargs) plot.set_dict_ax(0, fig_dict) if path_save_plot is not None: # TODO 23/06/2021 nie_k: PROBLEM WHEN KEY IS NONE Le chemin d’accès spécifié est introuvable: '' # TODO 26/06/2021 nie_k: refactor function using path_save_plot + fct. LIKE PARAMETER + KEYS + NAME FCT (hist, scatter, lineplot...) name_file = ''.join( [function_str.tuple_to_str(key, ''), 'evol_estimation']) plot.save_plot(name_save_file=name_file) return plots
def hist(self, column_name_draw, separators_plot=None, separators_filter=None, palette='PuOr', hue=None, bins=20, binrange=None, stat='count', multiple="stack", kde=False, path_save_plot=None): """ Semantics: histogram plot. Issue with seaborn: When writing overloading, always draw before using super(). Otherwise, the legend is not actualised. If it is, then seaborn's style in the legend will be erased. Args: column_name_draw: separators_plot: separators_filter: palette: hue: bins: binrange (pair): borns of the ax. stat: Aggregate statistic to compute in each bin. 'count' shows the number of observations. 'frequency' shows the number of observations divided by the bin width. 'density' normalizes counts so that the area of the histogram is 1. 'probability' normalizes counts so that the sum of the bar heights is 1. multiple: Approach to resolving multiple elements when semantic mapping creates subsets. {“layer”, “dodge”, “stack”, “fill”} kde (bool): If True, compute a kernel density estimate to smooth the distribution and show on the plot as (one or more) line(s). Only relevant with univariate data. path_save_plot: Returns: """ # super call for gathering all separators together and having the group by done. separators, global_dict, keys = super().draw( separators_plot=separators_plot) keys = filter(separators, keys, separators_filter) plots = [] for key in keys: if key is None: # case where we cannot use groupby. data = global_dict separators = ["data used"] key = ["whole dataset"] # for the title else: data = global_dict.get_group(key) plot = APlot() plots.append(plot) # get the good palette (sliced avoiding white. palette = self.color_scheme(palette) sns.histplot(x=column_name_draw, bins=bins, hue=hue, multiple=multiple, binrange=binrange, legend='full', kde=kde, palette=palette, data=data, ax=plot._axs[0], stat=stat) fig_dict = self.get_dict_fig(separators, key) plot.set_dict_ax(0, fig_dict) if path_save_plot is not None: name_file = ''.join( [function_str.tuple_to_str(key, ''), 'evol_estimation']) plot.save_plot(name_save_file=name_file) return plots