rougier / scientific-visualization-book

An open access book on scientific visualization using python and matplotlib

Home Page:https://www.labri.fr/perso/nrougier/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

re: Textual contours example

anntzer opened this issue · comments

You may be interested by matplotlib/matplotlib#16171?

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.

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.

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.

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