From 948f63fade88bee27b545e12bd8ce667a192d9ee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pablo=20Gonz=C3=A1lez?= Date: Mon, 16 Jan 2023 17:00:24 +0100 Subject: [PATCH 1/5] updating plot to center it better --- quapy/plot.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/quapy/plot.py b/quapy/plot.py index cdb9b1e..7d032f1 100644 --- a/quapy/plot.py +++ b/quapy/plot.py @@ -212,6 +212,7 @@ def binary_bias_bins(method_names, true_prevs, estim_prevs, pos_class=1, title=N def error_by_drift(method_names, true_prevs, estim_prevs, tr_prevs, n_bins=20, error_name='ae', show_std=False, show_density=True, + show_legend=True, logscale=False, title=f'Quantification error as a function of distribution shift', vlines=None, @@ -234,6 +235,7 @@ def error_by_drift(method_names, true_prevs, estim_prevs, tr_prevs, :param error_name: a string representing the name of an error function (as defined in `quapy.error`, default is "ae") :param show_std: whether or not to show standard deviations as color bands (default is False) :param show_density: whether or not to display the distribution of experiments for each bin (default is True) + :param show_density: whether or not to display the legend of the chart (default is True) :param logscale: whether or not to log-scale the y-error measure (default is False) :param title: title of the plot (default is "Quantification error as a function of distribution shift") :param vlines: array-like list of values (default is None). If indicated, highlights some regions of the space @@ -306,7 +308,11 @@ def error_by_drift(method_names, true_prevs, estim_prevs, tr_prevs, if vlines: for vline in vlines: ax.axvline(vline, 0, 1, linestyle='--', color='k') - ax.set_xlim(0, max_x) + + if not show_legend: + ax.get_legend().remove() + + ax.set_xlim(min_x, max_x) ax.legend(loc='center left', bbox_to_anchor=(1, 0.5)) _save_or_show(savepath) From 7bcf8b24e9e08b05c3390f3667cb3482dfe93c1e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pablo=20Gonz=C3=A1lez?= Date: Mon, 16 Jan 2023 17:17:02 +0100 Subject: [PATCH 2/5] fixing bug --- quapy/plot.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/quapy/plot.py b/quapy/plot.py index 7d032f1..794fd4c 100644 --- a/quapy/plot.py +++ b/quapy/plot.py @@ -309,11 +309,11 @@ def error_by_drift(method_names, true_prevs, estim_prevs, tr_prevs, for vline in vlines: ax.axvline(vline, 0, 1, linestyle='--', color='k') - if not show_legend: - ax.get_legend().remove() ax.set_xlim(min_x, max_x) - ax.legend(loc='center left', bbox_to_anchor=(1, 0.5)) + + if not show_legend: + ax.legend(loc='center left', bbox_to_anchor=(1, 0.5)) _save_or_show(savepath) From c888346fcffd1f4f40843615148e6519a6e6419c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pablo=20Gonz=C3=A1lez?= Date: Tue, 17 Jan 2023 11:03:52 +0100 Subject: [PATCH 3/5] solving a bug in show_legend --- quapy/plot.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/quapy/plot.py b/quapy/plot.py index 794fd4c..c1a857e 100644 --- a/quapy/plot.py +++ b/quapy/plot.py @@ -312,7 +312,7 @@ def error_by_drift(method_names, true_prevs, estim_prevs, tr_prevs, ax.set_xlim(min_x, max_x) - if not show_legend: + if show_legend: ax.legend(loc='center left', bbox_to_anchor=(1, 0.5)) _save_or_show(savepath) From 50d886bffe7f3def0ce49388b299b915a4f40b5f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pablo=20Gonz=C3=A1lez?= Date: Wed, 18 Jan 2023 13:06:38 +0100 Subject: [PATCH 4/5] testing log scale --- quapy/plot.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/quapy/plot.py b/quapy/plot.py index c1a857e..7b2145f 100644 --- a/quapy/plot.py +++ b/quapy/plot.py @@ -4,6 +4,7 @@ from matplotlib.cm import get_cmap import numpy as np from matplotlib import cm from scipy.stats import ttest_ind_from_stats +from matplotlib.ticker import StrMethodFormatter, NullFormatter import quapy as qp @@ -256,6 +257,9 @@ def error_by_drift(method_names, true_prevs, estim_prevs, tr_prevs, # x_error function) and 'y' is the estim-test shift (computed as according to y_error) data = _join_data_by_drift(method_names, true_prevs, estim_prevs, tr_prevs, x_error, y_error, method_order) + if method_order is None: + method_order = method_names + _set_colors(ax, n_methods=len(method_order)) bins = np.linspace(0, 1, n_bins+1) @@ -266,7 +270,11 @@ def error_by_drift(method_names, true_prevs, estim_prevs, tr_prevs, tr_test_drifts = data[method]['x'] method_drifts = data[method]['y'] if logscale: - method_drifts=np.log(1+method_drifts) + #method_drifts=np.log(1+method_drifts) + plt.yscale("log") + ax.yaxis.set_major_formatter(StrMethodFormatter('{x:.2f}')) + ax.yaxis.set_minor_formatter(StrMethodFormatter('{x:.2f}')) + inds = np.digitize(tr_test_drifts, bins, right=True) @@ -299,7 +307,7 @@ def error_by_drift(method_names, true_prevs, estim_prevs, tr_prevs, if show_density: ax.bar([ind * binwidth-binwidth/2 for ind in range(len(bins))], max_y*npoints/np.max(npoints), alpha=0.15, color='g', width=binwidth, label='density') - + ax.set(xlabel=f'Distribution shift between training set and test sample', ylabel=f'{error_name.upper()} (true distribution, predicted distribution)', title=title) From f10a3139d9594b38a95234ac8513c5473baaded4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pablo=20Gonz=C3=A1lez?= Date: Wed, 18 Jan 2023 14:53:46 +0100 Subject: [PATCH 5/5] changes to plots again --- quapy/plot.py | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/quapy/plot.py b/quapy/plot.py index 7b2145f..2e41413 100644 --- a/quapy/plot.py +++ b/quapy/plot.py @@ -4,7 +4,7 @@ from matplotlib.cm import get_cmap import numpy as np from matplotlib import cm from scipy.stats import ttest_ind_from_stats -from matplotlib.ticker import StrMethodFormatter, NullFormatter +from matplotlib.ticker import ScalarFormatter import quapy as qp @@ -270,11 +270,11 @@ def error_by_drift(method_names, true_prevs, estim_prevs, tr_prevs, tr_test_drifts = data[method]['x'] method_drifts = data[method]['y'] if logscale: - #method_drifts=np.log(1+method_drifts) - plt.yscale("log") - ax.yaxis.set_major_formatter(StrMethodFormatter('{x:.2f}')) - ax.yaxis.set_minor_formatter(StrMethodFormatter('{x:.2f}')) - + ax.set_yscale("log") + ax.yaxis.set_major_formatter(ScalarFormatter()) + ax.yaxis.set_minor_formatter(ScalarFormatter()) + ax.yaxis.get_major_formatter().set_scientific(False) + ax.yaxis.get_minor_formatter().set_scientific(False) inds = np.digitize(tr_test_drifts, bins, right=True) @@ -305,8 +305,14 @@ def error_by_drift(method_names, true_prevs, estim_prevs, tr_prevs, ax.fill_between(xs, ys-ystds, ys+ystds, alpha=0.25) if show_density: - ax.bar([ind * binwidth-binwidth/2 for ind in range(len(bins))], + ax2 = ax.twinx() + ax2.bar([ind * binwidth-binwidth/2 for ind in range(len(bins))], max_y*npoints/np.max(npoints), alpha=0.15, color='g', width=binwidth, label='density') + #ax2.set_ylabel("bar data") + ax2.set_ylim(0,1) + ax2.spines['right'].set_color('g') + ax2.tick_params(axis='y', colors='g') + #ax2.yaxis.set_visible(False) ax.set(xlabel=f'Distribution shift between training set and test sample', ylabel=f'{error_name.upper()} (true distribution, predicted distribution)', @@ -321,8 +327,8 @@ def error_by_drift(method_names, true_prevs, estim_prevs, tr_prevs, ax.set_xlim(min_x, max_x) if show_legend: - ax.legend(loc='center left', bbox_to_anchor=(1, 0.5)) - + fig.legend(loc='right') + _save_or_show(savepath)