Matplotlib does not update plot when used in an IDE (PyCharm)

Viewed 6674

I am new to python and just installed pyCharm and tried to run a test example given to the following question: How to update a plot in matplotlib?

This example updates the plot to animate a moving sine signal. Instead of replotting, it updates the data of the plot object. It works in command line but the figure does not show up when run in PyCharm. Adding plt.show(block=True) at the end of the script brings up the figure but this time it wont update.

Any ideas?

2 Answers

As noted by ImportanceOfBeingErnest in a separate question, on some systems, it is vital to add these two lines to the beginning of the code from the OP's example:

import matplotlib
matplotlib.use("TkAgg")

This may render the calls to plt.ion and plt.ioff unnecessary; the code now works without them on my system.

Related