scientific-visualization-book icon indicating copy to clipboard operation
scientific-visualization-book copied to clipboard

re: Textual contours example

Open anntzer opened this issue 5 years ago • 4 comments

You may be interested by https://github.com/matplotlib/matplotlib/pull/16171?

anntzer avatar Nov 06 '20 12:11 anntzer

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.

rougier avatar Nov 06 '20 18:11 rougier

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.

anntzer avatar Nov 06 '20 18:11 anntzer

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.

rougier avatar Nov 06 '20 21:11 rougier

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

anntzer avatar Nov 06 '20 22:11 anntzer