From 6ea55caf670b382b980e708c12aea46cb5ccf988 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?In=C3=AAs=20Cachola?= Date: Thu, 15 May 2025 10:54:54 +0100 Subject: [PATCH] Backport PR #29895: The 'lines.markeredgecolor' now doesn't interfere on the color of errorbar caps --- lib/matplotlib/axes/_axes.py | 2 +- lib/matplotlib/tests/test_axes.py | 26 ++++++++++++++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/lib/matplotlib/axes/_axes.py b/lib/matplotlib/axes/_axes.py index 91dcf5a58acf..a13d797bfed8 100644 --- a/lib/matplotlib/axes/_axes.py +++ b/lib/matplotlib/axes/_axes.py @@ -3780,7 +3780,7 @@ def _upcast_err(err): 'zorder', 'rasterized'): if key in kwargs: eb_cap_style[key] = kwargs[key] - eb_cap_style['color'] = ecolor + eb_cap_style["markeredgecolor"] = ecolor barcols = [] caplines = {'x': [], 'y': []} diff --git a/lib/matplotlib/tests/test_axes.py b/lib/matplotlib/tests/test_axes.py index e3fc1ada9941..e5f99cf38cd4 100644 --- a/lib/matplotlib/tests/test_axes.py +++ b/lib/matplotlib/tests/test_axes.py @@ -9618,3 +9618,29 @@ def test_axes_set_position_external_bbox_unchanged(fig_test, fig_ref): ax_test.set_position([0.25, 0.25, 0.5, 0.5]) assert (bbox.x0, bbox.y0, bbox.width, bbox.height) == (0.0, 0.0, 1.0, 1.0) ax_ref = fig_ref.add_axes([0.25, 0.25, 0.5, 0.5]) + + +def test_caps_color(): + # Creates a simple plot with error bars and a specified ecolor + x = np.linspace(0, 10, 10) + mpl.rcParams['lines.markeredgecolor'] = 'green' + ecolor = 'red' + + fig, ax = plt.subplots() + errorbars = ax.errorbar(x, np.sin(x), yerr=0.1, ecolor=ecolor) + + # Tests if the caps have the specified color + for cap in errorbars[2]: + assert mcolors.same_color(cap.get_edgecolor(), ecolor) + + +def test_caps_no_ecolor(): + # Creates a simple plot with error bars without specifying ecolor + x = np.linspace(0, 10, 10) + mpl.rcParams['lines.markeredgecolor'] = 'green' + fig, ax = plt.subplots() + errorbars = ax.errorbar(x, np.sin(x), yerr=0.1) + + # Tests if the caps have the default color (blue) + for cap in errorbars[2]: + assert mcolors.same_color(cap.get_edgecolor(), "blue") pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy