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

Open
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

useidemaisachola
Copy link

PR summary

-This change was necessary to resolve a bug: Fixes #29780
-Color of errorbar caps now it's not affected by 'lines.markeredgecolor'.

  • The reason behind the implementation is as follows:
    The initial issue arose when the caps of the error bars were unintentionally adopting the color red, which was set globally in mpl.rcParams under the 'lines.markeredgecolor' parameter. This global setting was being applied to all markers, including the caps of error bars, causing the caps to appear red even when that wasn't intended.
    The root cause of the problem was that the marker edge color defined globally (mpl.rcParams['lines.markeredgecolor']) was being inherited by the caps as part of the error bar plot. This caused the color of the caps to match the global red color, even when only the error bars were supposed to be red (through the ecolor parameter).
    To solve this, we needed to ensure that the caps would use the specified ecolor independently of the global mpl.rcParams['lines.markeredgecolor']. This was achieved by setting the marker edge color for the caps separately, rather than relying on the global configuration.
    The files that suffered alterations were _axes.py and test_axes.py.

PR checklist

…olor

To solve this, we needed to ensure that the caps would use the
specified ecolor independently of the global
mpl.rcParams['lines.markeredgecolor']. This was achieved by
setting the marker edge color for the caps separately, rather
 than relying on the global configuration.
@tacaswell
Copy link
Member

The default value of lines.markeredgecolor 'auto' which means "follow the color", but when setting it to a color it stops following the color of the line.

This is the correct fix.

@tacaswell
Copy link
Member

@useidemaisachola Thank you for this fix and the test! If you can clean up the linting/whitespace issues I think this can be merged straight away.

@tacaswell tacaswell added this to the v3.10.2 milestone Apr 11, 2025
@useidemaisachola
Copy link
Author

@tacaswell ok, i can solve them! One question as this is my first PR - after i resolve the problems with the spaces i have to commit and open another PR? Or it's possible to still use this one?

@QuLogic
Copy link
Member

QuLogic commented Apr 12, 2025

You should continue on your branch, and pushing it here will update this PR.

@useidemaisachola
Copy link
Author

@QuLogic Ok, thank you!

@useidemaisachola
Copy link
Author

@tacaswell I resolved the problem with the spaces! Now it's giving some kind of error with the version of python on windows... It is something that i have to change?

@rcomer
Copy link
Member

rcomer commented Apr 20, 2025

@useidemaisachola that Azure Windows test can be flakey. The failure is not caused by your change. I have re-run it to see if we can be lucky the second time.

@useidemaisachola
Copy link
Author

so, now i have to resolve the conflits?

@rcomer
Copy link
Member

rcomer commented Apr 25, 2025

so, now i have to resolve the conflits?

Yes, but if you are not comfortable doing that we can handle it for you. It looks like you and and another recent PR have added new tests in the same place, so it's just a case of making sure we keep both.

@useidemaisachola
Copy link
Author

Already resolved the conflit but I guess i leaved an extra line at the end of the file or something like that, because it's failing one test... it's that?

@timhoffm
Copy link
Member

I took the liberty to remove the extra line at the end. Tests should pass now.

Comment on lines +9740 to +9746
y = np.sin(x)
yerr = 0.1
mpl.rcParams['lines.markeredgecolor'] = 'green'
ecolor = 'red'

fig, ax = plt.subplots()
errorbars = ax.errorbar(x, y, yerr=yerr, ecolor=ecolor, fmt='o', capsize=5)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
y = np.sin(x)
yerr = 0.1
mpl.rcParams['lines.markeredgecolor'] = 'green'
ecolor = 'red'
fig, ax = plt.subplots()
errorbars = ax.errorbar(x, y, yerr=yerr, ecolor=ecolor, fmt='o', capsize=5)
mpl.rcParams['lines.markeredgecolor'] = 'green'
ecolor = 'red'
fig, ax = plt.subplots()
errorbars = ax.errorbar(x, sin(x), yerr=0.1, ecolor=ecolor)
  • Inlining the only-once used parameters make the code more compact.
  • The fmt and capsize parameters don't have an influence. Leaving them out keeps the code more readable.

Comment on lines +9757 to +9762
y = np.sin(x)
yerr = 0.1
mpl.rcParams['lines.markeredgecolor'] = 'green'

fig, ax = plt.subplots()
errorbars = ax.errorbar(x, y, yerr=yerr, fmt='o', capsize=5)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As above:

Suggested change
y = np.sin(x)
yerr = 0.1
mpl.rcParams['lines.markeredgecolor'] = 'green'
fig, ax = plt.subplots()
errorbars = ax.errorbar(x, y, yerr=yerr, fmt='o', capsize=5)
mpl.rcParams['lines.markeredgecolor'] = 'green'
fig, ax = plt.subplots()
errorbars = ax.errorbar(x, np.sin(x), yerr=0.1)

@useidemaisachola
Copy link
Author

ok, thank you for the tips and the help!

@ksunden ksunden modified the milestones: v3.10.2, v3.10.3 May 2, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Bug]: Setting 'lines.markeredgecolor' affects color of errorbar caps.
6 participants