From a4a8ea797e53962b33ec97642166a26b35df856b Mon Sep 17 00:00:00 2001 From: thetestspecimen Date: Wed, 20 Mar 2024 23:14:49 +0200 Subject: [PATCH 1/6] Fix BUG-7023 allow style when using errorbars --- pandas/plotting/_matplotlib/core.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/pandas/plotting/_matplotlib/core.py b/pandas/plotting/_matplotlib/core.py index dbd2743345a38..063d344022caa 100644 --- a/pandas/plotting/_matplotlib/core.py +++ b/pandas/plotting/_matplotlib/core.py @@ -974,6 +974,9 @@ def _plot( kwds["xerr"] = np.array(kwds.get("xerr")) if "yerr" in kwds: kwds["yerr"] = np.array(kwds.get("yerr")) + # GH 7023 allow setting plot style when using errorbars + if style is not None: + kwds["fmt"] = style return ax.errorbar(x, y, **kwds) else: # prevent style kwarg from going to errorbar, where it is unsupported From da9dae85ed40aced785f1daeb27eea9b1d047728 Mon Sep 17 00:00:00 2001 From: thetestspecimen Date: Fri, 22 Mar 2024 20:13:59 +0200 Subject: [PATCH 2/6] Tests for BUG-7023 allow style when using errorbars --- pandas/tests/plotting/frame/test_frame.py | 41 +++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/pandas/tests/plotting/frame/test_frame.py b/pandas/tests/plotting/frame/test_frame.py index 25669ce75953f..c70bb103f256a 100644 --- a/pandas/tests/plotting/frame/test_frame.py +++ b/pandas/tests/plotting/frame/test_frame.py @@ -1959,6 +1959,47 @@ def _check_errorbar_color(containers, expected, has_err="has_xerr"): _check_has_errorbars(ax, xerr=0, yerr=1) _check_errorbar_color(ax.containers, "green", has_err="has_yerr") + def test_errorbar_plot_line_style(self): + def _check_line_style(ax, expected): + for line_num, line_data in enumerate(ax.get_lines()): + received = [ + line_data.get_linestyle(), + line_data.get_color(), + line_data.get_marker(), + line_data.get_markeredgecolor(), + line_data.get_markerfacecolor(), + ] + assert received == expected[line_num] + + # GH 7023 + data1 = np.array([9, 3, 5, 1, 7]) + data2 = np.array([1, 2, 2, 8, 4]) + err1 = data1 * 0.1 + err2 = data2 * 0.1 + df = DataFrame({"data1": data1, "data2": data2}) + err_x = DataFrame({"data1": err1, "data2": err2}) + err_y = DataFrame({"data1": err2, "data2": err1}) + expected = [[":", "r", "o", "r", "r"], ["--", "g", "v", "g", "g"]] + + # check for single line + ax = df["data1"].plot(xerr=err_x["data1"], yerr=err_y["data1"], style="or:") + num_lines = len(ax.get_lines()) + _check_has_errorbars(ax, xerr=num_lines, yerr=num_lines) + _check_line_style(ax, expected) + + # check for two lines on a single plot + ax = df.plot(xerr=err_x, yerr=err_y, style=["or:", "vg--"], subplots=False) + num_lines = len(ax.get_lines()) + _check_has_errorbars(ax, xerr=num_lines, yerr=num_lines) + _check_line_style(ax, expected) + + # check for two lines, each on separate subplots + axes = df.plot(xerr=err_x, yerr=err_y, style=["or:", "vg--"], subplots=True) + for ax_num, ax in enumerate(axes): + num_lines = len(ax.get_lines()) + _check_has_errorbars(ax, xerr=num_lines, yerr=num_lines) + _check_line_style(ax, [expected[ax_num]]) + def test_scatter_unknown_colormap(self): # GH#48726 df = DataFrame({"a": [1, 2, 3], "b": 4}) From 72fd7e594e3d3f13c5e04f8a3fbbc2ad8d560c80 Mon Sep 17 00:00:00 2001 From: thetestspecimen Date: Fri, 22 Mar 2024 20:43:52 +0200 Subject: [PATCH 3/6] Docs for BUG-7023 allow style when using errorbars --- doc/source/whatsnew/v3.0.0.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/source/whatsnew/v3.0.0.rst b/doc/source/whatsnew/v3.0.0.rst index ef561d50066d1..6812e10dc7fbb 100644 --- a/doc/source/whatsnew/v3.0.0.rst +++ b/doc/source/whatsnew/v3.0.0.rst @@ -372,7 +372,7 @@ Period Plotting ^^^^^^^^ -- +- Bug in :meth:`MPLPlot._plot` ignoring parameter ``style`` when using error bar parameters ``yerr`` or ``xerr`` (:issue:`7023`) - Groupby/resample/rolling From 7cbb7cc7f509127af85e8b2cd7659e81c2d2429f Mon Sep 17 00:00:00 2001 From: thetestspecimen Date: Sun, 21 Apr 2024 12:49:46 +0300 Subject: [PATCH 4/6] Update whatsnew to use correct docs reference --- doc/source/whatsnew/v3.0.0.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/source/whatsnew/v3.0.0.rst b/doc/source/whatsnew/v3.0.0.rst index 0669bec80fc5c..45320fc45cb38 100644 --- a/doc/source/whatsnew/v3.0.0.rst +++ b/doc/source/whatsnew/v3.0.0.rst @@ -422,7 +422,7 @@ Plotting ^^^^^^^^ - Bug in :meth:`.DataFrameGroupBy.boxplot` failed when there were multiple groupings (:issue:`14701`) - Bug in :meth:`DataFrame.plot` that causes a shift to the right when the frequency multiplier is greater than one. (:issue:`57587`) -- Bug in :meth:`MPLPlot._plot` ignoring parameter ``style`` when using error bar parameters ``yerr`` or ``xerr`` (:issue:`7023`) +- Bug in :meth:`DataFrame.plot` ignoring parameter ``style`` when using error bar parameters ``yerr`` or ``xerr`` (:issue:`7023`) Groupby/resample/rolling ^^^^^^^^^^^^^^^^^^^^^^^^ From 34d99ecd79e05d4d10156fd9eeb1203591cc2bbd Mon Sep 17 00:00:00 2001 From: thetestspecimen Date: Sun, 21 Apr 2024 12:52:36 +0300 Subject: [PATCH 5/6] Remove description from GitHub reference --- pandas/plotting/_matplotlib/core.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/plotting/_matplotlib/core.py b/pandas/plotting/_matplotlib/core.py index bd19c12441435..f0da8d9406775 100644 --- a/pandas/plotting/_matplotlib/core.py +++ b/pandas/plotting/_matplotlib/core.py @@ -974,7 +974,7 @@ def _plot( kwds["xerr"] = np.array(kwds.get("xerr")) if "yerr" in kwds: kwds["yerr"] = np.array(kwds.get("yerr")) - # GH 7023 allow setting plot style when using errorbars + # GH 7023 if style is not None: kwds["fmt"] = style return ax.errorbar(x, y, **kwds) From b6b8d9341e4209e54606f45137952f84ef940e2c Mon Sep 17 00:00:00 2001 From: thetestspecimen Date: Sun, 21 Apr 2024 13:01:50 +0300 Subject: [PATCH 6/6] Precommit - sort whatsnew entries alphabetically --- doc/source/whatsnew/v3.0.0.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/source/whatsnew/v3.0.0.rst b/doc/source/whatsnew/v3.0.0.rst index 45320fc45cb38..be470ba1af671 100644 --- a/doc/source/whatsnew/v3.0.0.rst +++ b/doc/source/whatsnew/v3.0.0.rst @@ -421,8 +421,8 @@ Period Plotting ^^^^^^^^ - Bug in :meth:`.DataFrameGroupBy.boxplot` failed when there were multiple groupings (:issue:`14701`) -- Bug in :meth:`DataFrame.plot` that causes a shift to the right when the frequency multiplier is greater than one. (:issue:`57587`) - Bug in :meth:`DataFrame.plot` ignoring parameter ``style`` when using error bar parameters ``yerr`` or ``xerr`` (:issue:`7023`) +- Bug in :meth:`DataFrame.plot` that causes a shift to the right when the frequency multiplier is greater than one. (:issue:`57587`) Groupby/resample/rolling ^^^^^^^^^^^^^^^^^^^^^^^^