-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Fix IndexError for pyplot.legend() when plotting empty bar chart with label #13551
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks good to me. Could you add a test to make sure this doesn't break again in the future? Just the two lines of code in #13003 inside a new test should be enough.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good modulo adding the test
lib/matplotlib/tests/test_legend.py
Outdated
@@ -477,6 +477,14 @@ def test_handler_numpoints(): | |||
ax.legend(numpoints=0.5) | |||
|
|||
|
|||
@image_comparison(baseline_images=['empty_bar_legend'], extensions=['svg']) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, this is failing because your the baseline image is a different size. But...
- try not to use svg for this sort of thing because we just rasterize to png anyway.
- we try not to do image comparisons if possible because they are expensive in terms of time and bandwidth. Its my undertstanding this crashed before, so all you need for this to pass is for this not to crash (i.e. a smoketest). Suggest you simply remove the image comaprison
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would say just get rid of the image comparison and the test image, I think it's good enough to just check the code runs without any errors.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for your comments. I will keep that in mind. In the future, how would I do image comparisons? I created the image using save_fig
and it seems to output in a different dimension.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I usually run the tests locally (make sure that in setup.cfg
you have compiled so that freetype is local) and then copy the resulting image into the baseline images...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Whoever merges please squash-merge
PR Summary
Resolves #13003. Allows an empty bar chart to be created with a legend.
PR Checklist