Thanks to visit codestin.com
Credit goes to github.com

Skip to content

The 'lines.markeredgecolor' now doesn't interfere on the color of errorbar caps #29895

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
May 15, 2025
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