Closed oscargus closed 1 year ago
This looks great, thank you! Do you know the different between plt.draw() and ax.figure.canvas.draw()?
Also, perhaps raising an error in case of no passed texts would be better than simply returning? Or at least a warning...
plt.draw
does canvas.draw_idle
which "Request a widget redraw once control returns to the GUI event loop." So I guess that if it is used outside of a GUI event loop, or if the GUI does not idle before the next step, it may not behave as expected.
I modified it now to use figure.draw_without_rendering
, which only does the positioning of things, without the actual figure generation.
One may argue about the empty list case. In my library I only sometimes get texts that I want to apply adjust_text
to. So for me it was convenient to just get that list in, empty or not. Not a big deal to add a check in my code, but since the previous behavior was that it did work with empty lists, I would probably opt for that (unless there starts to come in bug reports about nothing happening that originates from people passing in empty lists...).
(Now, I run adjust_text
a configurable number of times, so I realize that I still may want to check if it is empty or not for a bit of micro-optimization, but anyway...)
Oh, and I think that returning 0 is a quite good indication that nothing has happened.
OK, I am happy to merge this! Thanks a lot. I'll use the figure.draw_without_rendering method in the future... Matplotlib has too many variations on the "draw" idea!
Fixes #140 Fixes #137 (I also had this issue)
The problem was that the way I was using it, from inside a library, for some reason the draw didn't happen with plt.draw(). Now, it should always work when passing
ax
(and seems to work for me even without it).Modifying my own code to deal with #137 is simple, but considering that more people seem to be affected, I added a minor fix for that as well.
(Seems like my editor modified another line as well, hope that is OK...)