From 7ed7c9b2e94a9da4d0d763c389bde9b612354b75 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pablo=20Gonz=C3=A1lez?= Date: Wed, 18 Jan 2023 16:05:40 +0100 Subject: [PATCH 1/3] changing the logaritmic scale --- quapy/plot.py | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/quapy/plot.py b/quapy/plot.py index 2e41413..15c7be5 100644 --- a/quapy/plot.py +++ b/quapy/plot.py @@ -5,6 +5,7 @@ import numpy as np from matplotlib import cm from scipy.stats import ttest_ind_from_stats from matplotlib.ticker import ScalarFormatter +import math import quapy as qp @@ -272,9 +273,8 @@ def error_by_drift(method_names, true_prevs, estim_prevs, tr_prevs, if logscale: 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) + ax.minorticks_off() inds = np.digitize(tr_test_drifts, bins, right=True) @@ -307,12 +307,10 @@ def error_by_drift(method_names, true_prevs, estim_prevs, tr_prevs, if show_density: 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") + npoints/np.sum(npoints), alpha=0.15, color='g', width=binwidth, label='density') 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)', @@ -325,9 +323,13 @@ def error_by_drift(method_names, true_prevs, estim_prevs, tr_prevs, ax.set_xlim(min_x, max_x) + if logscale: + #nice scale for the logaritmic axis + ax.set_ylim(0,10 ** math.ceil(math.log10(max_y))) + if show_legend: - fig.legend(loc='right') + fig.legend(bbox_to_anchor=(1.05, 1), loc="upper right") _save_or_show(savepath) @@ -549,7 +551,7 @@ def _join_data_by_drift(method_names, true_prevs, estim_prevs, tr_prevs, x_error method_order = [] for method, test_prevs_i, estim_prevs_i, tr_prev_i in zip(method_names, true_prevs, estim_prevs, tr_prevs): - tr_prev_i = np.repeat(tr_prev_i.reshape(1, -1), repeats=test_prevs_i.shape[0], axis=0) + tr_prev_i = np.repeat(tr_prevs.reshape(1, -1), repeats=test_prevs_i.shape[0], axis=0) tr_test_drifts = x_error(test_prevs_i, tr_prev_i) data[method]['x'] = np.concatenate([data[method]['x'], tr_test_drifts]) From 8da4b4c5f399c764bf96bda36004ebb57f05c548 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pablo=20Gonz=C3=A1lez?= Date: Wed, 18 Jan 2023 16:12:38 +0100 Subject: [PATCH 2/3] placing the legend --- quapy/plot.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/quapy/plot.py b/quapy/plot.py index 15c7be5..358bf45 100644 --- a/quapy/plot.py +++ b/quapy/plot.py @@ -306,9 +306,10 @@ def error_by_drift(method_names, true_prevs, estim_prevs, tr_prevs, if show_density: ax2 = ax.twinx() + densities = npoints/np.sum(npoints) ax2.bar([ind * binwidth-binwidth/2 for ind in range(len(bins))], - npoints/np.sum(npoints), alpha=0.15, color='g', width=binwidth, label='density') - ax2.set_ylim(0,1) + densities, alpha=0.15, color='g', width=binwidth, label='density') + ax2.set_ylim(0,max(densities)) ax2.spines['right'].set_color('g') ax2.tick_params(axis='y', colors='g') @@ -329,7 +330,9 @@ def error_by_drift(method_names, true_prevs, estim_prevs, tr_prevs, if show_legend: - fig.legend(bbox_to_anchor=(1.05, 1), loc="upper right") + fig.legend(loc='lower center', + bbox_to_anchor=(1, 0.5), + ncol=(len(method_names)+1)//2) _save_or_show(savepath) From 38aa42e4c52ef6434ce02918c8263b76372ffedb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pablo=20Gonz=C3=A1lez?= Date: Wed, 18 Jan 2023 16:44:56 +0100 Subject: [PATCH 3/3] fixing a bug --- quapy/plot.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/quapy/plot.py b/quapy/plot.py index 358bf45..061ecdc 100644 --- a/quapy/plot.py +++ b/quapy/plot.py @@ -554,7 +554,7 @@ def _join_data_by_drift(method_names, true_prevs, estim_prevs, tr_prevs, x_error method_order = [] for method, test_prevs_i, estim_prevs_i, tr_prev_i in zip(method_names, true_prevs, estim_prevs, tr_prevs): - tr_prev_i = np.repeat(tr_prevs.reshape(1, -1), repeats=test_prevs_i.shape[0], axis=0) + tr_prev_i = np.repeat(tr_prev_i.reshape(1, -1), repeats=test_prevs_i.shape[0], axis=0) tr_test_drifts = x_error(test_prevs_i, tr_prev_i) data[method]['x'] = np.concatenate([data[method]['x'], tr_test_drifts])