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

re: Textual contours example #4

Open
anntzer opened this issue Nov 6, 2020 · 4 comments
Open

re: Textual contours example #4

anntzer opened this issue Nov 6, 2020 · 4 comments

Comments

@anntzer
Copy link

anntzer commented Nov 6, 2020

You may be interested by matplotlib/matplotlib#16171?

@rougier
Copy link
Owner

rougier commented Nov 6, 2020

I can help testing if it is what you mean. For the textual contour example, I simply used TextPath along the contour path but it is kind if limited because there may be sharp turns in the contour that make text unreadable. I guess for the general case, straight labels are probably the best option but I can check what are the alternatives in other software/libraries. And I can send you my code of course.

@anntzer
Copy link
Author

anntzer commented Nov 6, 2020

It's mostly just that Matplotlib's current contouring code has some defects wrt. the way the breaks in the contour are determined (on the image on the left (which I guess is "plain matplotlib"?) the breaks are clearly too big), and also there may be nicer ways to format the texts (e.g. using ScalarFormatter is likely more robust (e.g. wrt. trailing zeros) than a fixed format string, and will use mathtext if that's what you have in the rcParams (so in your image the "minus" will be an actual minus sign, not a dash -- actually that may be nicer on the image on the right too)).

I don't know to what extent you directly reused Matplotlib's contour code as opposed to rewriting things from scratch, but wanted to point out that if you did reuse Matplotlib's contour code then there may be some low-lying improvements possible for you as well.

@rougier
Copy link
Owner

rougier commented Nov 6, 2020

I reused the contour directly from the contour.collections then I interpolate the vertices to fit the text. I think one (big) difference is that I use TextPath whose size is in data space and it simplifies everything in my case. Not sure about the origin of the large gap you mention but I can imagine it might be quite hard to fit "perfectly" a regular text.

@anntzer
Copy link
Author

anntzer commented Nov 6, 2020

Yes, that looks good. The point about using mathtext (even manually, if you prefer) remains, though.
Other than that, feel free to close this.

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

No branches or pull requests

2 participants