I am trying to use matplotlib.animation.FuncAnimation to display an animated graph (not through the terminal). I am using PyCharm Professional 2019.2 on macOS 10.14.6
I haven't found any solutions that would work for PyCharm on macOS.
I've tried a couple of things:
Using an alternative to
FuncAnimate
Animating with matplotlib without animation functionAdding
import matplotlib
matplotlib.use("TkAgg")
as suggested in Matplotlib animation not displaying in PyCharm. This causes my PyCharm to crash and brings me to the macOS login screen.
import datetime as dt
import matplotlib.pyplot as plt
import matplotlib.animation as animation
# Create figure for plotting
figure = plt.figure()
axis = figure.add_subplot(1, 1, 1)
xs = []
ys = []
# This function is called periodically from FuncAnimation
def animate(i, xs, ys):
# Add x and y to lists
xs.append(dt.datetime.now().strftime('%H:%M:%S.%f'))
ys.append(dt.datetime.now().strftime('%H:%M:%S.%f'))
# Limit x and y lists to 20 items
xs = xs[-20:]
ys = ys[-20:]
# Draw x and y lists
axis.clear()
axis.plot(xs, ys)
# Format plot
plt.xticks(rotation=45, ha='right')
plt.subplots_adjust(bottom=0.30)
plt.title('Data over Time')
plt.ylabel('Data')
# Set up plot to call animate() function periodically
ani = animation.FuncAnimation(figure, animate, fargs=(xs, ys), interval=1000)
plt.show()
This code just simply graphs a linear function based on time (both axes)
When compiling through the terminal, the graph is working flawlessly. PyCharm for some reason doesn't want to graph it. Any solutions for macOS?