Skip to content

Adding elinestyle property to errorbar #29879

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 22 commits into from
Apr 30, 2025
Merged

Conversation

hasanrashid
Copy link
Contributor

This PR is intended to add an elinestyle parameter to the errorbar function. The issue is described here: #29681

The errorbar object contains horizontal and vertical lines to demonstrate error ranges on a graph. At the moment, the line style of the errorbar can only be changed by calling the set_linestyle function of the line objects representing the horizontal and vertical error lines individually.

The elinestyle property will provide a method to assign the line style of the error lines when the errorbar is created.
the proposed use of the updated errorbar is as follows:

Sample data
x = np.linspace(0, 10, 10)  # X values
y = np.sin(x)  # Y values
yerr = 0.2  # Error values for Y
xerr = 0.1  # Error values for X

# Create figure and axis
fig, ax = plt.subplots()

# Plot error bars
eb1 = ax.errorbar(x, y, xerr=xerr, yerr=yerr,elinestyle ='-.', fmt='o', capsize=5, capthick=2, color='blue', label='Data with Error')
eb2 = ax.errorbar(x, y, xerr=xerr, yerr=yerr,elinestyle ='dotted', fmt='o', capsize=5, capthick=2, color='blue', label='Data with Error')

  • Why is this change necessary?
  • What problem does it solve?
  • What is the reasoning for this implementation?

PR checklist

@hasanrashid
Copy link
Contributor Author

Hey folks,

Worked on this: #29681

A few notes:

  • I used the set_linestyle function from within the errorbar function to apply the linestyle to the error lines
  • At the moment, the property applies the same style to both the x and y error line (if both are used). If it needs to be more granular- that can be done as well
  • I have not added any code examples to demonstrate this- seems like a simple property that the function message should be enough for, but let me know if it is needed

hasanrashid and others added 2 commits April 8, 2025 17:54
Co-authored-by: Tim Hoffmann <2836374+timhoffm@users.noreply.github.com>
Copy link
Member

@timhoffm timhoffm left a comment

Choose a reason for hiding this comment

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

You need to run python tools/boilerplate.py to update the errorbar signature for pyplot as well. This will fix the failing test.

Please also fix the formatting issues indicated by flake8.

Comment on lines 4120 to 4122
integration_max_step_scale=1.0,
integration_max_error_scale=1.0,
num_arrows=1,
Copy link
Member

Choose a reason for hiding this comment

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

did boilerplate.py do these changes? This should not be modified.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I believe so. I have not added anything to this file.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I ran boilerplate.py in another branch without any of my changes. These changes appear as a result.

Copy link
Member

Choose a reason for hiding this comment

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

Ok, I've opened a separate issue on this. For this PR, please just revert the unwanted modifications.

Copy link
Member

@QuLogic QuLogic Apr 16, 2025

Choose a reason for hiding this comment

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

Did you run it outside an environment with the current version installed? The script imports matplotlib, so the only way it would be out of sync would be if it was using a different version.

It seems like that's the case because elinestyle hasn't been added anywhere.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I was working on this branch using the conda environment mpl-dev in codespace

Copy link
Member

Choose a reason for hiding this comment

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

Are you definitely using Matplotlib installed from source?
https://matplotlib.org/devdocs/devel/development_setup.html#verify-the-installation

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hi. I will verify. I activated the condo envy and started working.

Copy link
Member

@rcomer rcomer Apr 16, 2025

Choose a reason for hiding this comment

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

Possibly you missed the install step then
https://matplotlib.org/devdocs/devel/development_setup.html#install-matplotlib-in-editable-mode

You will probably also need to set this before the install
#29852 (comment)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

"You will probably also need to set this before the install
#29852 (comment)"

Thank you. I was getting an error in codespace while running pytest. This seems to have fixed it, but I don't recall seeing it in the documentation

hasanrashid and others added 2 commits April 20, 2025 18:50
Co-authored-by: Elliott Sales de Andrade <quantum.analyst@gmail.com>
@timhoffm
Copy link
Member

There are still the strange removals in pyplot. Please fix this - either manually, or by getting the environment right so that boilerplate.py finds the correct sources.

@@ -3825,7 +3835,6 @@ def apply_mask(arrays, mask):
for axis in caplines:
for l in caplines[axis]:
self.add_line(l)

Copy link
Member

Choose a reason for hiding this comment

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

This looks like an accidental unrelated change. Let's not include this

@QuLogic QuLogic added this to the v3.11.0 milestone Apr 30, 2025
@QuLogic QuLogic merged commit 192e935 into matplotlib:main Apr 30, 2025
40 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[ENH]: Add parameter 'error_linestyle' to plt.errorbar()
4 participants