From a789df4410b328d0fa291f5b46dfbfb0639eafc2 Mon Sep 17 00:00:00 2001 From: Nikhil Bhavikatti <36807179+nikhilbhavikatti@users.noreply.github.com> Date: Mon, 21 Oct 2024 10:15:12 +0200 Subject: [PATCH] Kwargs optimization of high dimensional plots (#28) --- uadapy/plotting/plots1D.py | 20 +++++++------- uadapy/plotting/plots2D.py | 55 +++++++++++++++++--------------------- uadapy/plotting/plotsND.py | 33 +++++++++-------------- 3 files changed, 45 insertions(+), 63 deletions(-) diff --git a/uadapy/plotting/plots1D.py b/uadapy/plotting/plots1D.py index 96bd86f..4bbaab4 100644 --- a/uadapy/plotting/plots1D.py +++ b/uadapy/plotting/plots1D.py @@ -43,11 +43,9 @@ def _setup_plot(distributions, n_samples, seed, fig=None, axs=None, colors=None, Axes object(s) to use for plotting. If None, new axes will be created. colors : list or None, optional List of colors to use for each distribution. If None, Glasbey colors will be used. - **kwargs : additional keyword arguments - Additional optional arguments. - - colorblind_safe : bool, optional - If True, the plot will use colors suitable for colorblind individuals. - Default is False. + colorblind_safe : bool, optional + If True, the plot will use colors suitable for colorblind individuals. + Default is False. Returns ------- @@ -122,7 +120,7 @@ def plot_1d_distribution( distrib_colors=None, vert=True, colorblind_safe=False, - show_plot=True, + show_plot=False, dot_size=0, **kwargs): """ @@ -316,7 +314,7 @@ def generate_boxplot(distributions, distrib_colors=None, vert=True, colorblind_safe=False, - show_plot=True, + show_plot=False, **kwargs): """ Plot box plots for samples drawn from given distributions. @@ -375,7 +373,7 @@ def generate_violinplot(distributions, distrib_colors=None, vert=True, colorblind_safe=False, - show_plot=True, + show_plot=False, **kwargs): """ Plot violin plots for samples drawn from given distributions. @@ -433,7 +431,7 @@ def generate_dotplot(distributions, distrib_colors=None, vert=True, colorblind_safe=False, - show_plot=True, + show_plot=False, dot_size=0): """ Plot dot plots for samples drawn from given distributions. @@ -491,7 +489,7 @@ def generate_stripplot(distributions, distrib_colors=None, vert=True, colorblind_safe=False, - show_plot=True, + show_plot=False, dot_size=0): """ Plot strip plots for samples drawn from given distributions. @@ -551,7 +549,7 @@ def generate_swarmplot(distributions, distrib_colors=None, vert=True, colorblind_safe=False, - show_plot=True, + show_plot=False, dot_size=0): """ Plot swarm plots for samples drawn from given distributions. diff --git a/uadapy/plotting/plots2D.py b/uadapy/plotting/plots2D.py index f8a9b31..4ad19fb 100644 --- a/uadapy/plotting/plots2D.py +++ b/uadapy/plotting/plots2D.py @@ -4,7 +4,7 @@ from numpy import ma from matplotlib import ticker -def plot_samples(distributions, n_samples, seed=55, **kwargs): +def plot_samples(distributions, n_samples, seed=55, xlabel=None, ylabel=None, title=None, show_plot=False): """ Plot samples from the given distribution. If several distributions should be plotted together, an array can be passed to this function. @@ -17,15 +17,15 @@ def plot_samples(distributions, n_samples, seed=55, **kwargs): Number of samples per distribution. seed : int Seed for the random number generator for reproducibility. It defaults to 55 if not provided. - **kwargs : additional keyword arguments - Additional optional plotting arguments. - - xlabel : string, optional - label for x-axis. - - ylabel : string, optional - label for y-axis. - - show_plot : bool, optional - If True, display the plot. - Default is False. + xlabel : string, optional + label for x-axis. + ylabel : string, optional + label for y-axis. + title : string, optional + title for the plot. + show_plot : bool, optional + If True, display the plot. + Default is False. Returns ------- @@ -40,25 +40,24 @@ def plot_samples(distributions, n_samples, seed=55, **kwargs): for d in distributions: samples = d.sample(n_samples, seed) plt.scatter(x=samples[:,0], y=samples[:,1]) - if 'xlabel' in kwargs: - plt.xlabel(kwargs['xlabel']) - if 'ylabel' in kwargs: - plt.ylabel(kwargs['ylabel']) - if 'title' in kwargs: - plt.title(kwargs['title']) + if xlabel: + plt.xlabel(xlabel) + if ylabel: + plt.ylabel(ylabel) + if title: + plt.title(title) # Get the current figure and axes fig = plt.gcf() axs = plt.gca() - show_plot = kwargs.get('show_plot', False) if show_plot: fig.tight_layout() plt.show() return fig, axs -def plot_contour(distributions, resolution=128, ranges=None, quantiles:list=None, seed=55, **kwargs): +def plot_contour(distributions, resolution=128, ranges=None, quantiles:list=None, seed=55, show_plot=False): """ Plot contour plots for samples drawn from given distributions. @@ -74,11 +73,9 @@ def plot_contour(distributions, resolution=128, ranges=None, quantiles:list=None List of quantiles to use for determining isovalues. If None, the 99.7%, 95%, and 68% quantiles are used. seed : int Seed for the random number generator for reproducibility. It defaults to 55 if not provided. - **kwargs : additional keyword arguments - Additional optional plotting arguments. - - show_plot : bool, optional - If True, display the plot. - Default is False. + show_plot : bool, optional + If True, display the plot. + Default is False. Returns ------- @@ -144,7 +141,6 @@ def plot_contour(distributions, resolution=128, ranges=None, quantiles:list=None fig = plt.gcf() axs = plt.gca() - show_plot = kwargs.get('show_plot', False) if show_plot: fig.tight_layout() plt.show() @@ -152,7 +148,7 @@ def plot_contour(distributions, resolution=128, ranges=None, quantiles:list=None return fig, axs def plot_contour_bands(distributions, n_samples, resolution=128, ranges=None, quantiles: list = None, seed=55, - **kwargs): + show_plot=False): """ Plot contour bands for samples drawn from given distributions. @@ -170,11 +166,9 @@ def plot_contour_bands(distributions, n_samples, resolution=128, ranges=None, qu List of quantiles to use for determining isovalues. If None, the 99.7%, 95%, and 68% quantiles are used. seed : int Seed for the random number generator for reproducibility. It defaults to 55 if not provided. - **kwargs : additional keyword arguments - Additional optional plotting arguments. - - show_plot : bool, optional - If True, display the plot. - Default is False. + show_plot : bool, optional + If True, display the plot. + Default is False. Returns ------- @@ -247,7 +241,6 @@ def plot_contour_bands(distributions, n_samples, resolution=128, ranges=None, qu fig = plt.gcf() axs = plt.gca() - show_plot = kwargs.get('show_plot', False) if show_plot: fig.tight_layout() plt.show() diff --git a/uadapy/plotting/plotsND.py b/uadapy/plotting/plotsND.py index 79f7b80..04497d6 100644 --- a/uadapy/plotting/plotsND.py +++ b/uadapy/plotting/plotsND.py @@ -3,7 +3,7 @@ from uadapy import Distribution import uadapy.plotting.utils as utils -def plot_samples(distributions, n_samples, seed=55, **kwargs): +def plot_samples(distributions, n_samples, seed=55, show_plot=False): """ Plot samples from the multivariate distribution as a SLOM. @@ -15,11 +15,9 @@ def plot_samples(distributions, n_samples, seed=55, **kwargs): Number of samples per distribution. seed : int Seed for the random number generator for reproducibility. It defaults to 55 if not provided. - **kwargs : additional keyword arguments - Additional optional plotting arguments. - - show_plot : bool, optional - If True, display the plot. - Default is False. + show_plot : bool, optional + If True, display the plot. + Default is False. Returns ------- @@ -64,14 +62,13 @@ def plot_samples(distributions, n_samples, seed=55, **kwargs): fig = plt.gcf() axs = plt.gca() - show_plot = kwargs.get('show_plot', False) if show_plot: fig.tight_layout() plt.show() return fig, axs -def plot_contour(distributions, n_samples, resolution=128, ranges=None, quantiles: list = None, seed=55, **kwargs): +def plot_contour(distributions, n_samples, resolution=128, ranges=None, quantiles: list = None, seed=55, show_plot=False): """ Visualizes a multidimensional distribution in a matrix of contour plots. @@ -89,11 +86,9 @@ def plot_contour(distributions, n_samples, resolution=128, ranges=None, quantile List of quantiles to use for determining isovalues. If None, the 99.7%, 95%, and 68% quantiles are used. seed : int Seed for the random number generator for reproducibility. It defaults to 55 if not provided. - **kwargs : additional keyword arguments - Additional optional plotting arguments. - - show_plot : bool, optional - If True, display the plot. - Default is False. + show_plot : bool, optional + If True, display the plot. + Default is False. Returns ------- @@ -192,7 +187,6 @@ def plot_contour(distributions, n_samples, resolution=128, ranges=None, quantile fig = plt.gcf() axs = plt.gca() - show_plot = kwargs.get('show_plot', False) if show_plot: fig.tight_layout() plt.show() @@ -200,7 +194,7 @@ def plot_contour(distributions, n_samples, resolution=128, ranges=None, quantile return fig, axs def plot_contour_samples(distributions, n_samples, resolution=128, ranges=None, quantiles: list = None, seed=55, - **kwargs): + show_plot=False): """ Visualizes a multidimensional distribution in a matrix visualization where the upper diagonal contains contour plots and the lower diagonal contains scatterplots. @@ -219,11 +213,9 @@ def plot_contour_samples(distributions, n_samples, resolution=128, ranges=None, List of quantiles to use for determining isovalues. If None, the 99.7%, 95%, and 68% quantiles are used. seed : int Seed for the random number generator for reproducibility. It defaults to 55 if not provided. - **kwargs : additional keyword arguments - Additional optional plotting arguments. - - show_plot : bool, optional - If True, display the plot. - Default is False. + show_plot : bool, optional + If True, display the plot. + Default is False. Returns ------- @@ -324,7 +316,6 @@ def plot_contour_samples(distributions, n_samples, resolution=128, ranges=None, fig = plt.gcf() axs = plt.gca() - show_plot = kwargs.get('show_plot', False) if show_plot: fig.tight_layout() plt.show()