From eff9e7a30a99cc66e3074d9ec53744f9708b36dd Mon Sep 17 00:00:00 2001 From: Jiwoo Lee Date: Tue, 21 Nov 2023 13:22:45 -0800 Subject: [PATCH 1/2] more options added for legend box control --- .../parallel_coordinate_plot_lib.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/pcmdi_metrics/graphics/parallel_coordinate_plot/parallel_coordinate_plot_lib.py b/pcmdi_metrics/graphics/parallel_coordinate_plot/parallel_coordinate_plot_lib.py index 8c37181a3..d126f678c 100644 --- a/pcmdi_metrics/graphics/parallel_coordinate_plot/parallel_coordinate_plot_lib.py +++ b/pcmdi_metrics/graphics/parallel_coordinate_plot/parallel_coordinate_plot_lib.py @@ -33,6 +33,8 @@ def parallel_coordinate_plot( colormap="viridis", num_color=20, legend_off=False, + legend_ncol=6, + legend_bbox_to_anchor=(0.5, -0.14), logo_rect=None, logo_off=False, model_names2=None, @@ -77,6 +79,8 @@ def parallel_coordinate_plot( - `colormap`: string, default='viridis', matplotlib colormap - `num_color`: integer, default=20, how many color to use. - `legend_off`: bool, default=False, turn off legend + - `legend_ncol`: integer, default=6, number of columns for legend text + - `legend_bbox_to_anchor`: tuple, defulat=(0.5, -0.14), set legend box location - `logo_rect`: sequence of float. The dimensions [left, bottom, width, height] of the new Axes. All quantities are in fractions of figure width and height. Optional. - `logo_off`: bool, default=False, turn off PMP logo @@ -336,7 +340,8 @@ def parallel_coordinate_plot( ax.set_title(title, fontsize=18) if not legend_off: - ax.legend(loc="upper center", ncol=6, bbox_to_anchor=(0.5, -0.14)) + #ax.legend(loc="upper center", ncol=6, bbox_to_anchor=(0.5, -0.14)) + ax.legend(loc="upper center", ncol=legend_ncol, bbox_to_anchor=legend_bbox_to_anchor) if not logo_off: fig, ax = add_logo(fig, ax, logo_rect) @@ -396,7 +401,7 @@ def _data_transform( else: ymins = np.repeat(ymin, N) - ymeds = np.nanmedian(ys, axis=0) # median + ymeds = np.nanmedian(ys, axis=0) # median ymean = np.nanmean(ys, axis=0) # mean if vertical_center is not None: From 24c1e5e556fe430085f3c10fcf1bb8640ccf6562 Mon Sep 17 00:00:00 2001 From: Jiwoo Lee Date: Tue, 21 Nov 2023 14:04:06 -0800 Subject: [PATCH 2/2] pre-commit fix --- .../parallel_coordinate_plot_lib.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/pcmdi_metrics/graphics/parallel_coordinate_plot/parallel_coordinate_plot_lib.py b/pcmdi_metrics/graphics/parallel_coordinate_plot/parallel_coordinate_plot_lib.py index d126f678c..74f674957 100644 --- a/pcmdi_metrics/graphics/parallel_coordinate_plot/parallel_coordinate_plot_lib.py +++ b/pcmdi_metrics/graphics/parallel_coordinate_plot/parallel_coordinate_plot_lib.py @@ -340,8 +340,10 @@ def parallel_coordinate_plot( ax.set_title(title, fontsize=18) if not legend_off: - #ax.legend(loc="upper center", ncol=6, bbox_to_anchor=(0.5, -0.14)) - ax.legend(loc="upper center", ncol=legend_ncol, bbox_to_anchor=legend_bbox_to_anchor) + # ax.legend(loc="upper center", ncol=6, bbox_to_anchor=(0.5, -0.14)) + ax.legend( + loc="upper center", ncol=legend_ncol, bbox_to_anchor=legend_bbox_to_anchor + ) if not logo_off: fig, ax = add_logo(fig, ax, logo_rect) @@ -401,7 +403,7 @@ def _data_transform( else: ymins = np.repeat(ymin, N) - ymeds = np.nanmedian(ys, axis=0) # median + ymeds = np.nanmedian(ys, axis=0) # median ymean = np.nanmean(ys, axis=0) # mean if vertical_center is not None: