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

Skip to content

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

Merged
merged 3 commits into from
Mar 2, 2019

Conversation

choyiny
Copy link
Contributor

@choyiny choyiny commented Feb 28, 2019

PR Summary

Resolves #13003. Allows an empty bar chart to be created with a legend.

PR Checklist

  • Has Pytest style unit tests
  • Code is Flake 8 compliant
  • New features are documented, with examples if plot related
  • Documentation is sphinx and numpydoc compliant
  • Added an entry to doc/users/next_whats_new/ if major new feature (follow instructions in README.rst there)
  • Documented in doc/api/api_changes.rst if API changed in a backward-incompatible way

Copy link
Member

@dstansby dstansby left a 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.

Copy link
Member

@jklymak jklymak left a 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

@@ -477,6 +477,14 @@ def test_handler_numpoints():
ax.legend(numpoints=0.5)


@image_comparison(baseline_images=['empty_bar_legend'], extensions=['svg'])
Copy link
Member

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...

  1. try not to use svg for this sort of thing because we just rasterize to png anyway.
  2. 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

Copy link
Member

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.

Copy link
Contributor Author

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.

Copy link
Member

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...

Copy link
Member

@dstansby dstansby left a 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

@jklymak jklymak merged commit a06ed93 into matplotlib:master Mar 2, 2019
@choyiny choyiny deleted the 13003-empty-bar-fix branch March 2, 2019 22:07
@choyiny choyiny restored the 13003-empty-bar-fix branch March 2, 2019 22:07
@QuLogic QuLogic added this to the v3.2.0 milestone Mar 3, 2019
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.

IndexError thrown by pyplot.legend() when plotting empty bar chart with label
4 participants