From a205b880d472ab8346e4fa1d419f9fd1d192b801 Mon Sep 17 00:00:00 2001 From: Ratish Panda Date: Tue, 26 Mar 2024 23:47:34 +0530 Subject: [PATCH 1/5] Fixed plot_trace legend overwriting --- arviz/plots/backends/matplotlib/traceplot.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/arviz/plots/backends/matplotlib/traceplot.py b/arviz/plots/backends/matplotlib/traceplot.py index 7b6d6b8e07..ea4752ad5d 100644 --- a/arviz/plots/backends/matplotlib/traceplot.py +++ b/arviz/plots/backends/matplotlib/traceplot.py @@ -439,8 +439,8 @@ def plot_trace( [], [], label="combined", **dealiase_sel_kwargs(plot_kwargs, chain_prop, -1) ), ) - ax.figure.axes[0].legend(handles=handles, title="chain", loc="upper right") - + ax.figure.axes[1].legend(handles=handles, title="chain", loc="upper right") + if axes is None: axes = np.array(ax.figure.axes).reshape(-1, 2) From 8920d3552e97c616549ddef1860058c5c063dc7e Mon Sep 17 00:00:00 2001 From: Ratish Panda Date: Sun, 31 Mar 2024 15:06:51 +0530 Subject: [PATCH 2/5] Modified base_tests/trace_plot_matplotlib for legend fix --- arviz/tests/base_tests/test_plots_matplotlib.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arviz/tests/base_tests/test_plots_matplotlib.py b/arviz/tests/base_tests/test_plots_matplotlib.py index c45b7085ac..75da2b15dd 100644 --- a/arviz/tests/base_tests/test_plots_matplotlib.py +++ b/arviz/tests/base_tests/test_plots_matplotlib.py @@ -260,7 +260,7 @@ def test_plot_trace_legend(compact, combined): axes = plot_trace( idata, var_names=["home", "atts_star"], compact=compact, combined=combined, legend=True ) - assert axes[0, 0].get_legend() + assert axes[0, 1].get_legend() compact_legend = axes[1, 0].get_legend() if compact: assert axes.shape == (2, 2) From d60b68cd099b0a63adc65be0f55c7d3acc356696 Mon Sep 17 00:00:00 2001 From: Ratish Panda Date: Thu, 4 Apr 2024 23:57:53 +0530 Subject: [PATCH 3/5] formatted with black --- arviz/plots/backends/matplotlib/traceplot.py | 2 +- doc/source/conf.py | 13 ++++++++++++- doc/sphinxext/gallery_generator.py | 3 ++- 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/arviz/plots/backends/matplotlib/traceplot.py b/arviz/plots/backends/matplotlib/traceplot.py index d771aceffc..b00baa5daa 100644 --- a/arviz/plots/backends/matplotlib/traceplot.py +++ b/arviz/plots/backends/matplotlib/traceplot.py @@ -441,7 +441,7 @@ def plot_trace( ), ) ax.figure.axes[1].legend(handles=handles, title="chain", loc="upper right") - + if axes is None: axes = np.array(ax.figure.axes).reshape(-1, 2) diff --git a/doc/source/conf.py b/doc/source/conf.py index 9601b99fe4..71fa5d223d 100644 --- a/doc/source/conf.py +++ b/doc/source/conf.py @@ -99,7 +99,18 @@ autodoc_typehints = "none" numpydoc_xref_param_type = True numpydoc_xref_ignore = { - "of", "or", "optional", "default", "1D", "2D", "3D", "n-dimensional", "K", "M", "N", "S", + "of", + "or", + "optional", + "default", + "1D", + "2D", + "3D", + "n-dimensional", + "K", + "M", + "N", + "S", } numpydoc_xref_aliases = { "DataArray": ":class:`~xarray.DataArray`", diff --git a/doc/sphinxext/gallery_generator.py b/doc/sphinxext/gallery_generator.py index c850c82af8..d06e6b53a8 100644 --- a/doc/sphinxext/gallery_generator.py +++ b/doc/sphinxext/gallery_generator.py @@ -5,6 +5,7 @@ Also inspired in bokeh's bokeh_gallery sphinxext. """ + import glob import os import os.path as op @@ -222,7 +223,7 @@ def overlay_description(self): elif self.apitext != "": return "{title} using `{apitext}`".format(title=self.title, apitext=self.apitext) return self.title - + @property def alt_text(self): if self._alt_text != "": From c7c1e7399777c70145ef305ff6474c65eb95b02e Mon Sep 17 00:00:00 2001 From: Ratish P Date: Sun, 7 Apr 2024 17:13:40 +0530 Subject: [PATCH 4/5] Update CHANGELOG.md --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3ab834f8da..7198757a53 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,8 @@ ### Maintenance and fixes +- Move chain legend in `trace_plot` to first trace plot instead of density plot to avoid overwriting density plot legend and modify test for checking chain legend in `trace_plot` appropriately ([2334](https://github.com/arviz-devs/arviz/pull/2334)) + ### Deprecation ### Documentation From 83746ba09c55c1e04fbd6bde05f84f42875188a1 Mon Sep 17 00:00:00 2001 From: Oriol Abril-Pla Date: Mon, 8 Apr 2024 16:40:42 +0200 Subject: [PATCH 5/5] shorten changelog entry --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7198757a53..279e3f4f21 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,7 +6,7 @@ ### Maintenance and fixes -- Move chain legend in `trace_plot` to first trace plot instead of density plot to avoid overwriting density plot legend and modify test for checking chain legend in `trace_plot` appropriately ([2334](https://github.com/arviz-devs/arviz/pull/2334)) +- Fix legend overwriting issue in `plot_trace` ([2334](https://github.com/arviz-devs/arviz/pull/2334)) ### Deprecation