cphyc / matplotlib-label-lines

Label line using matplotlib.
MIT License
301 stars 28 forks source link

Removing the underlying path/line instead of having a white rectangle #32

Closed RemDelaporteMathurin closed 3 years ago

RemDelaporteMathurin commented 3 years ago

Hi all,

Thank you for that nice package I've been using for a while now.

I still think that this feature should be included in matplotlib. I've raised an issue there. See: https://github.com/matplotlib/matplotlib/issues/19406

I think that improving this package even further would be to replace the use of a white rectangle by actually removing the underlying lines. Exactly the way it's done for matplotlib.pyplot.clabel(inline=True).

What do you guys think ? I think that's a feature many users (me included) would like to see implemented in matplotlib.

I'd be very happy to participate in any global effort towards this goal 😄

cphyc commented 3 years ago

Hi and thanks for the report.

I am totally open to suggestions to improve this package and I am not particularly satisfied with the fact we are currently "hiding" the line behind a white patch (e.g. it utterly breaks when using a non-white background).

I don't know what approach would be best, directly have your solution implemented in matplotlib as a new artist or merge it in this package, then merge the package into matplotlib?

RemDelaporteMathurin commented 3 years ago

Tbh my "solution" was nothing more than a proof of principle. It doesn't work with non-monotonous 2D lines for instance. But that's the idea.

I don't know what approach would be best, directly have your solution implemented in matplotlib as a new artist or merge it in this package, then merge the package into matplotlib?

I guess it depends how different the final solution will be from this package. And tbh I haven't read your source code in details to know for sure.

If adapting this package is easier and the final product can be easily merged in matplotlib then hell yeah why not

cphyc commented 3 years ago

Here's a demo using this https://matplotlib.org/3.1.1/tutorials/advanced/patheffects_guide.html#making-an-artist-stand-out (in practice, we should rather use a white outline rather than a grey one).

What do you think?

demo

RemDelaporteMathurin commented 3 years ago

This seems nice! I can see some very specific cases where it won't work (like with a non-white background or a gradient-coloured background) but these are very rare I reckon.

I had an issue though (perhaps I shall open another issue for that ?) when assigning custom x locations, the labels were not rotated anymore. Any clue ?

cphyc commented 3 years ago

Would you mind filling another issue?

RemDelaporteMathurin commented 3 years ago

Would you mind filling another issue?

see Issue #33

cphyc commented 3 years ago

Could you have a shot at #34 and tell me if that would be a good solution?

cphyc commented 3 years ago

Closing this as this should be now fixed as of v0.4.0!