-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
[Bug]: .remove() on ErrorbarContainer object does not remove the corresponding item from the legend #25274
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
Comments
Hey, I am new to open-source projects, but I was wondering where I would go about creating a patch for this issue. |
Ok, I just added a patch for this bug. |
So I was not able to figure it out, but it looks like the crux of the problem appears to be that the self.remove_method is never correctly called on ErrorBar Container. This is perplexing, as for barh(BarContainer), the remove method successfully works. It also looks like BarContainer is only one Artist object, but ErrorBar Container is three. This is because ErrorBarContainer has children of Line2D and LineCollections(not sure why it is three), both of which are successfully called, hence why the line is not there, but it is still present on the legend. This line might still exist as well(I am not entirely sure),. After a call, it is also strange cause the ErrorBar object still contains three Artists, including Line2D and LineCollections. Once the ErrorBar container is successfully removed from self.containers, which is around line ~1300 on _base.py, the problem will be solved. Although, ErrorBar still needs to remove ITSELF from self.containers, in order to stay in line with semantics. It is also supposed to note that this is not a rendering or updating issue, as the container's object still contains ErrorBarContainer. What likely happens is that both ErrorBar Container and BarContainer both inherit the same remove method, but likely due to their specific implementation, you cannot remove ErrorBar Container from containers from a self-reference point of view, at least the way this is currently written. These are probably the main files you should look into for fixing this bug: https://github.com/matplotlib/matplotlib/blob/main/lib/matplotlib/container.py Hopefully you all figure this out !! |
@Higgs32584 Thanks for the detailed look, and leaving some notes for others to follow... |
Hey man, I do not know if you can figure this out, but I could not. I left some notes for you to follow if necessary @rohitchouhan35 |
@Higgs32584 Thanks man, I'll look into it |
Bug summary
When I do
.remove()
onErrorbarContainer
objects returned fromAxes.errorbar()
, the objects are removed from the plot but the legend items are not removed.Code for reproduction
Actual outcome
test_errorbar_1.pdf
test_errorbar_2.pdf
Expected outcome
The legend in
test_errorbar_2.pdf
contains only one entry corresponding to the second call toax.errorbar()
, i.e., the label"bar"
.Additional information
I am not sure if this is the right way to remove the errorbar objects from the axes after their creation. Please correct me if I am doing it wrong or there is a better way.
As a side note, when I remove Line2D objects returned from
Axes.plot()
, the corresponding legend items also disappear, as one might expect. Maybe there is a problem specific to errorbar plots?Operating system
macOS Ventura 13.0
Matplotlib Version
3.6.2
Matplotlib Backend
MacOSX
Python version
3.10.9
Jupyter version
No response
Installation
conda
The text was updated successfully, but these errors were encountered: