This is basically the same issue as #6103, but I have found that the "correct" approach selectively fails on the macosx backend. I decided to open a separate issue because there's a lot going on in the original thread.
(BTW I do support the suggestion in the original thread that get_{x/y}ticklabels should implicitly draw so that it always returns a sensible result).
It occurs to me that this is maybe the same issue as #19197.
Indeed, s/ax.figure.canvas.draw()/ax.figure.draw(ax.figure.canvas.get_renderer())/ does produce the expected output, BUT, s/ax.figure.canvas.draw()/plt.draw() does not.
However, the plt.draw() from #19268 (comment) doesn't work with any interactive backends because it is using a draw_idle call: ax.figure.canvas.draw_idle(), and the event loop doesn't run to trigger a draw. I think we can close this as the macosx backend is consistent with the other backends and changing plt.draw() would be a separate issue.
I think in current matplotlib we are suggesting fig.draw_without_rendering() as an easy user-accessible way of calling a draw. Though I agree that if the users is calling for the ticks, we should do a draw to give them the ticks.
Activity
mwaskom commented on Jan 9, 2021
It occurs to me that this is maybe the same issue as #19197.
Indeed, s/ax.figure.canvas.draw()/ax.figure.draw(ax.figure.canvas.get_renderer())/ does produce the expected output, BUT, s/ax.figure.canvas.draw()/plt.draw() does not.
greglucas commented on Jan 10, 2022
The original issue was resolved by #21758
However, the plt.draw() from #19268 (comment) doesn't work with any interactive backends because it is using a draw_idle call: ax.figure.canvas.draw_idle(), and the event loop doesn't run to trigger a draw. I think we can close this as the macosx backend is consistent with the other backends and changing plt.draw() would be a separate issue.
jklymak commented on Jan 10, 2022
I think in current matplotlib we are suggesting fig.draw_without_rendering() as an easy user-accessible way of calling a draw. Though I agree that if the users is calling for the ticks, we should do a draw to give them the ticks.
greglucas commented on Mar 5, 2022
Closing as the original example is now fixed on main.
produces: