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

backend_pgf. Enable custom dashstyles in the pgf backend #1251

Merged
merged 1 commit into from Sep 18, 2012

Conversation

jenshnielsen
Copy link
Member

The following code produces lines with identical standard dashes using the pgf backend.

import matplotlib
matplotlib.use('pgf')
import matplotlib.pyplot as plt
import numpy as np
y = np.arange(10)

plt.plot(y,dashes=(5,1))
plt.plot(y*1.5,dashes=(2,2))
plt.plot(y*2,dashes=(1,5))
plt.legend(['line1','line2','line3'])
plt.savefig('test.pdf')
plt.savefig('test.pgf')

This happens because the pgf backend only takes the linestyle argument into account but ignores the dashes. In addition the dash length is scaled with the linewidth in the pgf backend. This is inconsistent with other backends (I tested pdf and agg) where it is independent of the linewidth. This pull request fixes both these issues.

@jenshnielsen
Copy link
Member Author

This does not work in all cases. I will update the pull request to fix it

@jenshnielsen
Copy link
Member Author

This should be a more general solution that always write the full dash_list and and the dash_offset. I believe the offset is normally zero, but just in case I have added it.

@jenshnielsen
Copy link
Member Author

@pwuertz what do you think about this change?

@ghost ghost assigned pwuertz Sep 18, 2012
@@ -497,18 +497,16 @@ def _print_pgf_path_styles(self, gc, rgbFace):
writeln(self.fh, r"\pgfsetstrokeopacity{%f}" % gc.get_alpha())

# line style
dash_offset,dash_list = gc.get_dashes()
Copy link
Contributor

Choose a reason for hiding this comment

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

For PEP8 compliance there should be a space after the comma.

@pwuertz
Copy link
Contributor

pwuertz commented Sep 18, 2012

Thanks for taking care of this! The way I implemented dashed lines was more or less a reverse engineered solution because I haven't found a documentation of how this function should behave.. and I didn't know about gc.get_dashes() ^^.

But one thing keeps me wondering.. when I increase the linewidth the distances between the dashes don't increase.. so if I use a "dottet" linestyle with a thick line it's actually vertically striped and not dotted :/. This is wrong from my point of view, but it seems to be the default behaviour in matplotlib. Your solution looks good!

@pwuertz
Copy link
Contributor

pwuertz commented Sep 18, 2012

Could you maybe squash these to a single commit?

@jenshnielsen
Copy link
Member Author

I Agree that the scaling with line width is more natural and I only implemented it like this to match the other backends.
Perhaps this should be changed in a more general way or some argument to the plot function should toggle the scaling with line width. Yes I will squash the commits.

… using get_dashes. Also dash lenght does no longer scale with line width consistent with other backends.
pwuertz pushed a commit that referenced this pull request Sep 18, 2012
backend_pgf: custom dashstyles and compliance with other backends
@pwuertz pwuertz merged commit dd05f0a into matplotlib:master Sep 18, 2012
@mdboom
Copy link
Member

mdboom commented Sep 18, 2012

I agree we should fix the scaling to line width issue, and fix it for all backends, but that should wait for the next release.

I consider this a bugfix for the PGFD backend. Any reason not to put it in 1.2.x?

@pwuertz
Copy link
Contributor

pwuertz commented Sep 18, 2012

No objections. It's the right thing to do because it matches the behaviour of the other backends. The best solution to solve the dash-style scaling is probably to account for the linewidth in gc.get_dashes(). This should then work for all the backends if they don't rely on hard-coded values as I did.

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.

None yet

3 participants