-
-
Notifications
You must be signed in to change notification settings - Fork 8k
Closed
Description
Platfrom/Tools Information:
Platform: Windows 10 x64
Python Version: 2.7.11
Python Distribution: Anaconda 2.5.0 (64-bit)
Matplotlib Version: 1.5.1
Issue Description:
When I use an event callback that updates a figure two (or more) times within the callback, only the last update on an element seems to be applied. Concretely, the plot is updated only when the event callback returns.
Example:
In the following example the expected outcome would be:
- A figure with an axis with title "1"
- When I press a key:
--i. "Loading" is printed to the console and the axis title is updated to "Loading"
--ii. After 3 seconds "2" is printed to the console and the axis title is updated to "2"
However, the observed outcome is:
- A figure with an axis with title "1"
- When I press a key:
--i. "Loading" is printed to the console, but the axis title is not updated
--ii. After 3 seconds "2" is printed to the console and the axis title is updated to "2"
from matplotlib import pyplot as plt
import time
def slow_plot(figure, axis):
print "Loading"
axis.set_title("Loading")
figure.canvas.draw()
time.sleep(3)
print "2"
axis.set_title("2")
figure.canvas.draw()
def main():
figure, axis = plt.subplots(1, 1)
axis.set_title("1")
figure.canvas.draw()
figure.show()
def on_key_press(event):
slow_plot(figure, axis)
figure.canvas.mpl_connect("key_press_event", on_key_press)
plt.show()
if __name__ == "__main__":
main()
Additional Information:
- This code works as expected if I step through it step by step using the debugger.
- Tried running the same piece of code on a Mac and I got the expected behavior.
- I remember something similar working as expected about a year ago, so maybe this bug was introduced with matplotlib 1.5.1, but I can't say for sure. I'll try installing 1.4.* versions when I get some time and update the info.
Metadata
Metadata
Assignees
Labels
No labels