Skip to content
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

Incorrect hatching in legend for PDF backend #4469

Closed
jpallister opened this issue May 25, 2015 · 6 comments
Closed

Incorrect hatching in legend for PDF backend #4469

jpallister opened this issue May 25, 2015 · 6 comments
Milestone

Comments

@jpallister
Copy link

When using hatching in a legend, the PDF backend does not draw the hatching if the previous label is empty:

from matplotlib import pyplot as plt

fig = plt.figure()

a = plt.Rectangle([0,0], 0, 0, facecolor="green", hatch="//")
b = plt.Rectangle([0,0], 0, 0, facecolor="blue", hatch="//")

fig.legend([a,b,a,b], ["","","",""])

plt.savefig("test.pdf")
plt.show()

The displayed legend (from plt.show) is:
image

The legend saved in the PDF is:
image

If one of the labels is non-empty:

fig.legend([a,b,a,b], ["","","X",""])

the following hatching is displayed correctly
image

@tacaswell tacaswell added this to the next point release milestone May 25, 2015
@tacaswell
Copy link
Member

weird.

attn @jkseppan

@tacaswell
Copy link
Member

I suspect that there is a graphics context which is not getting properly reset.

@jpallister
Copy link
Author

The following commit fixes the issue in this case:
232c50d

However, I don't know enough to say whether this is the right thing to do. The problem does seem to be the hatch pattern is not reapplied in the PDF backend though.

@tacaswell
Copy link
Member

@jpallister Great! I also do not know enough about the internals of pdf's to tell if that is the right solution (it seems a bit brittle as I think it depends on the order of the commands), but I am convinced that this is the right place.

Can you put in a PR with that commit and maybe add a test, (see #4472 for an example of adding a pdf only test). Even if this is not the final solution, having the commit in a PR greatly helps us with the review process.

@tacaswell
Copy link
Member

maybe related: #3023

@tacaswell
Copy link
Member

Closed by merging #4474

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants