------------------- Summation ------------
I want to animate 3+ graphs using FuncAnimation by using the same animation object to speed up the code.
What is the best way of achieve this? What am I doing wrong as my use of return a + b + c do not work as this is an unreported operand type for +?
------------------- Summation ------------
I am working on a project were I need to print data in real time, as the data is spred over different measurements do I need to separate them into different graphs both for ease of use and as they have widely shifting amplitudes.
There are a lot of examples out there how one animates one graph however not on how to animate several. The ones that I have found how to use FuncAnimation to update and animate multiple figures with matplotlib? https://www.reddit.com/r/learnpython/comments/4a0e8v/live_graphing_multiple_subplots_with_matplotlib/
And the one that I have had the most successes with is to create several subplots in one figure and animate that figure. I have sett up the following testprogram based on the first example I mentioned above.
import numpy as np
import matplotlib.pyplot as plt
from matplotlib.animation import FuncAnimation
x1 = np.arange(130, 190, 1)
x2 = np.arange(130, 190, 1)
x3 = np.arange(130, 190, 1)
test1 = 1 * np.sin(2 * np.pi * x1 / 10)
test2 = 2 * np.sin(2 * np.pi * x2 / 10)
test3 = 3 * np.sin(2 * np.pi * x3 / 10)
xa, xb, xc, y1, y2, y3 = [], [], [], [], [], []
fig = plt.figure(1)
ax1 = fig.add_subplot(131)
line1, = ax1.plot([], [])
ax1.set_xlabel('Samples')
ax1.set_ylabel('Amplitude')
ax1.set_title('Line 1')
ax2 = fig.add_subplot(132)
line2, = ax2.plot([], [])
ax2.grid(True)
ax2.set_xlabel('Samples')
ax2.set_ylabel('Amplitude')
ax2.set_title('Line 2')
ax3 = fig.add_subplot(133)
line3, = ax3.plot([], [])
ax3.grid(True)
ax3.set_xlabel('Samples')
ax3.set_ylabel('Amplitude')
ax3.set_title('Line 3')
def update_line_1(i):
xa.append(x1[i])
y1.append(test1[i])
line1.set_data(xa, y1)
return line1
def update_line_2(i):
xb.append(x2[i])
y2.append(test2[i])
line2.set_data(x2, y2)
return line2
def update_line_3(i):
xc.append(x3[i])
y3.append(test3[i])
line3.set_data(x3, y3)
return line3
def update_all(i):
a = update_line_1(i)
b = update_line_2(i)
c = update_line_3(i)
return a + b + c
animALL = FuncAnimation(fig, update_all, interval=50, blit=True)
plt.show()
However the use of return a + b + c do not work as this is an unreported operand type for +
TypeError: unsupported operand type(s) for +: 'Line2D' and 'Line2D'
As I am relative new to animate do I wounder if this is the right approach and if the knowledgeable community do know of a beter way or if one of you might help me understand what I am doing wrong with adding the uppdatering information for multiple subplots.