So there was this thread talking about why matplotlib does not show when executing
python myfile.py
The most popular answer was about resetting matplotlibrc
file. What would need to be reset in this file?
Also, some suggest to include matplotlib.use('TkAgg')
in the import. Below is my python file:
#myfile.py
import matplotlib
matplotlib.use('TkAgg')
import matplotlib.pyplot as plt
import numpy as np
def dyn_draw():
x = np.linspace(0, 6 * np.pi, 100)
y = np.sin(x)
plt.ion()
fig = plt.figure()
ax = fig.add_subplot(111)
line1, = ax.plot(x, y, 'r-') # Returns a tuple of line objects, thus the comma
for phase in np.linspace(0, 10 * np.pi, 500):
line1.set_ydata(np.sin(x + phase))
fig.canvas.draw()
fig.canvas.flush_events()
if __name__ == "__main__":
dyn_draw()
Running that with python myfile.py
, I get the following error:
ImportError: Cannot load backend 'TkAgg' which requires the 'tk' interactive framework, as 'headless' is currently running
Another thread here discussed this error. But the solution still does not work (i.e. restarting the kernel).
How to plot this particular python code with the python
command?