Skip to content
2 changes: 1 addition & 1 deletion lib/matplotlib/axes/_axes.py
Original file line number Diff line number Diff line change
Expand Up @@ -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': []}
Expand Down
28 changes: 28 additions & 0 deletions lib/matplotlib/tests/test_axes.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')]
Expand Down
Loading