Is there any way to draw to a plot within a function and then have the changes show up on the plot before the function is finished executing?
For instance, in this function I would like to get the window extent of the text, but the function gives the error Cannot get window extent w/o renderer
because at the time s.get_window_extent()
is called the text has not been drawn on the plot.
import matplotlib.pyplot as plt
import time
plt.ion()
myfig, myax = plt.subplots()
def plot_now():
s = myax.annotate("foo", [0.5, 0.5])
myfig.canvas.draw_idle()
s.get_window_extent()
plot_now()
I'm using iPython, python 2.7.6, matplotlib 1.4.3, and the Qt4Agg backend