diff --git a/lib/matplotlib/axes/_axes.py b/lib/matplotlib/axes/_axes.py index 3d7899885c59..db870072beb7 100644 --- a/lib/matplotlib/axes/_axes.py +++ b/lib/matplotlib/axes/_axes.py @@ -3726,7 +3726,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 91740bc02dee..3946c67e3f39 100644 --- a/lib/matplotlib/tests/test_axes.py +++ b/lib/matplotlib/tests/test_axes.py @@ -9733,6 +9733,34 @@ def test_bar_shape_mismatch(): plt.bar(x, height) +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") + + def test_pie_non_finite_values(): fig, ax = plt.subplots() df = [5, float('nan'), float('inf')]