animated subplots using matplotlib and info text with current values
up vote
0
down vote
favorite
I am trying to combine examples from here and here. info_text
is not working, not updating.
I am getting error:
AttributeError: 'list' object has no attribute 'set_animated'
Anyone knows why?
Here is my code:
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.animation as animation
from pprint import pprint
total_subplots = 2
# initialize the data arrays
#xdata, y1data, y2data = , ,
signals =list()
for i in range(0, total_subplots):
signals.append() # [,]
xdata = list()
ax = list()
lines = list()
info_text = list()
colors=['blue', 'red']
def data_gen():
t_max = 1000.0
t = 0
dt = 0.05
y = [''] * total_subplots
while t < t_max:
t += dt
y[0] = np.sin(2*np.pi*t) * np.exp(-t/10.)
y[1] = np.cos(2*np.pi*t) * np.exp(-t/10.)
# adapted the data generator to yield both sin and cos
yield t, y
def run(data):
# update the data
t, y = data
xdata.append(t)
for i in range(0, total_subplots):
signals[i].append(y[i])
# axis limits checking. Same as before, just for both axes
for i in range(len(ax)):
xmin, xmax = ax[i].get_xlim()
if t >= xmax:
ax[i].set_xlim(xmin, 2*xmax)
ax[i].figure.canvas.draw()
# update the data of both line objects
for i in range(len(lines)):
lines[i].set_data(xdata, signals[i])
text = 'Time = %.1f s nValue = %.1f'%(t, y[i])
info_text[i].set_text(text)
return lines, info_text
# Initialize
# create a figure with two subplots
#fig, (ax1, ax2) = plt.subplots(2,1)
fig = plt.figure()
for i in range(0, total_subplots):
axis = fig.add_subplot(2, 1, (i+1))
ax.append(axis)
# intialize two line objects (one in each axes)
line, = ax[i].plot(, , lw=2, color=colors[i])
lines.append(line)
# the same axes initalizations as before (just now we do it for both of them)
ax[i].set_ylim(-1.1, 1.1)
ax[i].set_xlim(0, 5)
ax[i].grid()
text = ax[i].text(0.05, 0.9, '', transform=ax[i].transAxes)
info_text.append(text)
# Run
ani = animation.FuncAnimation(fig, run,
data_gen,
interval=10,
blit=True,
repeat=False)
plt.show()
python matplotlib subplot data-generation livegraph
add a comment |
up vote
0
down vote
favorite
I am trying to combine examples from here and here. info_text
is not working, not updating.
I am getting error:
AttributeError: 'list' object has no attribute 'set_animated'
Anyone knows why?
Here is my code:
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.animation as animation
from pprint import pprint
total_subplots = 2
# initialize the data arrays
#xdata, y1data, y2data = , ,
signals =list()
for i in range(0, total_subplots):
signals.append() # [,]
xdata = list()
ax = list()
lines = list()
info_text = list()
colors=['blue', 'red']
def data_gen():
t_max = 1000.0
t = 0
dt = 0.05
y = [''] * total_subplots
while t < t_max:
t += dt
y[0] = np.sin(2*np.pi*t) * np.exp(-t/10.)
y[1] = np.cos(2*np.pi*t) * np.exp(-t/10.)
# adapted the data generator to yield both sin and cos
yield t, y
def run(data):
# update the data
t, y = data
xdata.append(t)
for i in range(0, total_subplots):
signals[i].append(y[i])
# axis limits checking. Same as before, just for both axes
for i in range(len(ax)):
xmin, xmax = ax[i].get_xlim()
if t >= xmax:
ax[i].set_xlim(xmin, 2*xmax)
ax[i].figure.canvas.draw()
# update the data of both line objects
for i in range(len(lines)):
lines[i].set_data(xdata, signals[i])
text = 'Time = %.1f s nValue = %.1f'%(t, y[i])
info_text[i].set_text(text)
return lines, info_text
# Initialize
# create a figure with two subplots
#fig, (ax1, ax2) = plt.subplots(2,1)
fig = plt.figure()
for i in range(0, total_subplots):
axis = fig.add_subplot(2, 1, (i+1))
ax.append(axis)
# intialize two line objects (one in each axes)
line, = ax[i].plot(, , lw=2, color=colors[i])
lines.append(line)
# the same axes initalizations as before (just now we do it for both of them)
ax[i].set_ylim(-1.1, 1.1)
ax[i].set_xlim(0, 5)
ax[i].grid()
text = ax[i].text(0.05, 0.9, '', transform=ax[i].transAxes)
info_text.append(text)
# Run
ani = animation.FuncAnimation(fig, run,
data_gen,
interval=10,
blit=True,
repeat=False)
plt.show()
python matplotlib subplot data-generation livegraph
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I am trying to combine examples from here and here. info_text
is not working, not updating.
I am getting error:
AttributeError: 'list' object has no attribute 'set_animated'
Anyone knows why?
Here is my code:
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.animation as animation
from pprint import pprint
total_subplots = 2
# initialize the data arrays
#xdata, y1data, y2data = , ,
signals =list()
for i in range(0, total_subplots):
signals.append() # [,]
xdata = list()
ax = list()
lines = list()
info_text = list()
colors=['blue', 'red']
def data_gen():
t_max = 1000.0
t = 0
dt = 0.05
y = [''] * total_subplots
while t < t_max:
t += dt
y[0] = np.sin(2*np.pi*t) * np.exp(-t/10.)
y[1] = np.cos(2*np.pi*t) * np.exp(-t/10.)
# adapted the data generator to yield both sin and cos
yield t, y
def run(data):
# update the data
t, y = data
xdata.append(t)
for i in range(0, total_subplots):
signals[i].append(y[i])
# axis limits checking. Same as before, just for both axes
for i in range(len(ax)):
xmin, xmax = ax[i].get_xlim()
if t >= xmax:
ax[i].set_xlim(xmin, 2*xmax)
ax[i].figure.canvas.draw()
# update the data of both line objects
for i in range(len(lines)):
lines[i].set_data(xdata, signals[i])
text = 'Time = %.1f s nValue = %.1f'%(t, y[i])
info_text[i].set_text(text)
return lines, info_text
# Initialize
# create a figure with two subplots
#fig, (ax1, ax2) = plt.subplots(2,1)
fig = plt.figure()
for i in range(0, total_subplots):
axis = fig.add_subplot(2, 1, (i+1))
ax.append(axis)
# intialize two line objects (one in each axes)
line, = ax[i].plot(, , lw=2, color=colors[i])
lines.append(line)
# the same axes initalizations as before (just now we do it for both of them)
ax[i].set_ylim(-1.1, 1.1)
ax[i].set_xlim(0, 5)
ax[i].grid()
text = ax[i].text(0.05, 0.9, '', transform=ax[i].transAxes)
info_text.append(text)
# Run
ani = animation.FuncAnimation(fig, run,
data_gen,
interval=10,
blit=True,
repeat=False)
plt.show()
python matplotlib subplot data-generation livegraph
I am trying to combine examples from here and here. info_text
is not working, not updating.
I am getting error:
AttributeError: 'list' object has no attribute 'set_animated'
Anyone knows why?
Here is my code:
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.animation as animation
from pprint import pprint
total_subplots = 2
# initialize the data arrays
#xdata, y1data, y2data = , ,
signals =list()
for i in range(0, total_subplots):
signals.append() # [,]
xdata = list()
ax = list()
lines = list()
info_text = list()
colors=['blue', 'red']
def data_gen():
t_max = 1000.0
t = 0
dt = 0.05
y = [''] * total_subplots
while t < t_max:
t += dt
y[0] = np.sin(2*np.pi*t) * np.exp(-t/10.)
y[1] = np.cos(2*np.pi*t) * np.exp(-t/10.)
# adapted the data generator to yield both sin and cos
yield t, y
def run(data):
# update the data
t, y = data
xdata.append(t)
for i in range(0, total_subplots):
signals[i].append(y[i])
# axis limits checking. Same as before, just for both axes
for i in range(len(ax)):
xmin, xmax = ax[i].get_xlim()
if t >= xmax:
ax[i].set_xlim(xmin, 2*xmax)
ax[i].figure.canvas.draw()
# update the data of both line objects
for i in range(len(lines)):
lines[i].set_data(xdata, signals[i])
text = 'Time = %.1f s nValue = %.1f'%(t, y[i])
info_text[i].set_text(text)
return lines, info_text
# Initialize
# create a figure with two subplots
#fig, (ax1, ax2) = plt.subplots(2,1)
fig = plt.figure()
for i in range(0, total_subplots):
axis = fig.add_subplot(2, 1, (i+1))
ax.append(axis)
# intialize two line objects (one in each axes)
line, = ax[i].plot(, , lw=2, color=colors[i])
lines.append(line)
# the same axes initalizations as before (just now we do it for both of them)
ax[i].set_ylim(-1.1, 1.1)
ax[i].set_xlim(0, 5)
ax[i].grid()
text = ax[i].text(0.05, 0.9, '', transform=ax[i].transAxes)
info_text.append(text)
# Run
ani = animation.FuncAnimation(fig, run,
data_gen,
interval=10,
blit=True,
repeat=False)
plt.show()
python matplotlib subplot data-generation livegraph
python matplotlib subplot data-generation livegraph
asked Nov 22 at 16:11
ioaniatr
9411
9411
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
up vote
1
down vote
accepted
I think you mean to return the iterable of artists for the animation. It should one single iterable though. E.g.
return lines + info_text
It works!! Thank you!! But, how actually makes it iterable this way?
– ioaniatr
Nov 23 at 14:39
Lists are iterable in python.
– ImportanceOfBeingErnest
Nov 23 at 14:41
I saw that it actually merge the 2 lists into one and looks like:[<matplotlib.lines.Line2D object>, <matplotlib.lines.Line2D object>,<matplotlib.text.Text object>, <matplotlib.text.Text object>]
, but it thought that it should be like:[<matplotlib.lines.Line2D object>, <matplotlib.text.Text object>, <matplotlib.lines.Line2D object>,<matplotlib.text.Text object>]
– ioaniatr
Nov 23 at 14:51
What's the difference?
– ImportanceOfBeingErnest
Nov 23 at 15:44
Maybe, it puts the wronginfo_text
into the wrong graph. Every graph has it owninfo_text
.
– ioaniatr
Nov 23 at 15:52
|
show 2 more comments
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
1
down vote
accepted
I think you mean to return the iterable of artists for the animation. It should one single iterable though. E.g.
return lines + info_text
It works!! Thank you!! But, how actually makes it iterable this way?
– ioaniatr
Nov 23 at 14:39
Lists are iterable in python.
– ImportanceOfBeingErnest
Nov 23 at 14:41
I saw that it actually merge the 2 lists into one and looks like:[<matplotlib.lines.Line2D object>, <matplotlib.lines.Line2D object>,<matplotlib.text.Text object>, <matplotlib.text.Text object>]
, but it thought that it should be like:[<matplotlib.lines.Line2D object>, <matplotlib.text.Text object>, <matplotlib.lines.Line2D object>,<matplotlib.text.Text object>]
– ioaniatr
Nov 23 at 14:51
What's the difference?
– ImportanceOfBeingErnest
Nov 23 at 15:44
Maybe, it puts the wronginfo_text
into the wrong graph. Every graph has it owninfo_text
.
– ioaniatr
Nov 23 at 15:52
|
show 2 more comments
up vote
1
down vote
accepted
I think you mean to return the iterable of artists for the animation. It should one single iterable though. E.g.
return lines + info_text
It works!! Thank you!! But, how actually makes it iterable this way?
– ioaniatr
Nov 23 at 14:39
Lists are iterable in python.
– ImportanceOfBeingErnest
Nov 23 at 14:41
I saw that it actually merge the 2 lists into one and looks like:[<matplotlib.lines.Line2D object>, <matplotlib.lines.Line2D object>,<matplotlib.text.Text object>, <matplotlib.text.Text object>]
, but it thought that it should be like:[<matplotlib.lines.Line2D object>, <matplotlib.text.Text object>, <matplotlib.lines.Line2D object>,<matplotlib.text.Text object>]
– ioaniatr
Nov 23 at 14:51
What's the difference?
– ImportanceOfBeingErnest
Nov 23 at 15:44
Maybe, it puts the wronginfo_text
into the wrong graph. Every graph has it owninfo_text
.
– ioaniatr
Nov 23 at 15:52
|
show 2 more comments
up vote
1
down vote
accepted
up vote
1
down vote
accepted
I think you mean to return the iterable of artists for the animation. It should one single iterable though. E.g.
return lines + info_text
I think you mean to return the iterable of artists for the animation. It should one single iterable though. E.g.
return lines + info_text
answered Nov 22 at 20:02
ImportanceOfBeingErnest
123k10125202
123k10125202
It works!! Thank you!! But, how actually makes it iterable this way?
– ioaniatr
Nov 23 at 14:39
Lists are iterable in python.
– ImportanceOfBeingErnest
Nov 23 at 14:41
I saw that it actually merge the 2 lists into one and looks like:[<matplotlib.lines.Line2D object>, <matplotlib.lines.Line2D object>,<matplotlib.text.Text object>, <matplotlib.text.Text object>]
, but it thought that it should be like:[<matplotlib.lines.Line2D object>, <matplotlib.text.Text object>, <matplotlib.lines.Line2D object>,<matplotlib.text.Text object>]
– ioaniatr
Nov 23 at 14:51
What's the difference?
– ImportanceOfBeingErnest
Nov 23 at 15:44
Maybe, it puts the wronginfo_text
into the wrong graph. Every graph has it owninfo_text
.
– ioaniatr
Nov 23 at 15:52
|
show 2 more comments
It works!! Thank you!! But, how actually makes it iterable this way?
– ioaniatr
Nov 23 at 14:39
Lists are iterable in python.
– ImportanceOfBeingErnest
Nov 23 at 14:41
I saw that it actually merge the 2 lists into one and looks like:[<matplotlib.lines.Line2D object>, <matplotlib.lines.Line2D object>,<matplotlib.text.Text object>, <matplotlib.text.Text object>]
, but it thought that it should be like:[<matplotlib.lines.Line2D object>, <matplotlib.text.Text object>, <matplotlib.lines.Line2D object>,<matplotlib.text.Text object>]
– ioaniatr
Nov 23 at 14:51
What's the difference?
– ImportanceOfBeingErnest
Nov 23 at 15:44
Maybe, it puts the wronginfo_text
into the wrong graph. Every graph has it owninfo_text
.
– ioaniatr
Nov 23 at 15:52
It works!! Thank you!! But, how actually makes it iterable this way?
– ioaniatr
Nov 23 at 14:39
It works!! Thank you!! But, how actually makes it iterable this way?
– ioaniatr
Nov 23 at 14:39
Lists are iterable in python.
– ImportanceOfBeingErnest
Nov 23 at 14:41
Lists are iterable in python.
– ImportanceOfBeingErnest
Nov 23 at 14:41
I saw that it actually merge the 2 lists into one and looks like:
[<matplotlib.lines.Line2D object>, <matplotlib.lines.Line2D object>,<matplotlib.text.Text object>, <matplotlib.text.Text object>]
, but it thought that it should be like: [<matplotlib.lines.Line2D object>, <matplotlib.text.Text object>, <matplotlib.lines.Line2D object>,<matplotlib.text.Text object>]
– ioaniatr
Nov 23 at 14:51
I saw that it actually merge the 2 lists into one and looks like:
[<matplotlib.lines.Line2D object>, <matplotlib.lines.Line2D object>,<matplotlib.text.Text object>, <matplotlib.text.Text object>]
, but it thought that it should be like: [<matplotlib.lines.Line2D object>, <matplotlib.text.Text object>, <matplotlib.lines.Line2D object>,<matplotlib.text.Text object>]
– ioaniatr
Nov 23 at 14:51
What's the difference?
– ImportanceOfBeingErnest
Nov 23 at 15:44
What's the difference?
– ImportanceOfBeingErnest
Nov 23 at 15:44
Maybe, it puts the wrong
info_text
into the wrong graph. Every graph has it own info_text
.– ioaniatr
Nov 23 at 15:52
Maybe, it puts the wrong
info_text
into the wrong graph. Every graph has it own info_text
.– ioaniatr
Nov 23 at 15:52
|
show 2 more comments
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53434792%2fanimated-subplots-using-matplotlib-and-info-text-with-current-values%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown