Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ssl/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python Matplotlib错误Line2d对象在tkinter回调中不可编辑错误未显示任何内容_Python_Animation_Matplotlib_Scipy - Fatal编程技术网

Python Matplotlib错误Line2d对象在tkinter回调中不可编辑错误未显示任何内容

Python Matplotlib错误Line2d对象在tkinter回调中不可编辑错误未显示任何内容,python,animation,matplotlib,scipy,Python,Animation,Matplotlib,Scipy,代码如下所示。我正在尝试使用前面计算的向量设置动画,一个图形窗口被打开,所以我知道它走了这么远,向量被正确计算。但是matplotlib只输出图形窗口,我不知道为什么。请帮忙 #finally animateing fig = plt.figure() ax = plt.axes(xlim = (-1000,1000) ,ylim = (-1000,1000))#limits were arbitrary #line = ax.plot([],[]) line, = ax.plot([], []

代码如下所示。我正在尝试使用前面计算的向量设置动画,一个图形窗口被打开,所以我知道它走了这么远,向量被正确计算。但是matplotlib只输出图形窗口,我不知道为什么。请帮忙

#finally animateing
fig = plt.figure()
ax = plt.axes(xlim = (-1000,1000) ,ylim = (-1000,1000))#limits were arbitrary
#line = ax.plot([],[])
line, = ax.plot([], [], lw=2)

# initialization function: plot the background of each frame
def init():
    line.set_data([], [])
    return line,


def animate(i):
 x = time_vec[i]
 y = complex_vec[i]
 #y1 = real_vec[i] 
 #y2 = modulus_vec[i]
 line.set_data(x,y)
 #line.set_data(x,y1)
 #line.set_data(x,y2) 
 return line,

animation_object = animation.FuncAnimation(fig, animate, init_func= init, frames = num_files,interval = 30, blit = True)

#turnn this line on to save as mp4
#anim.save("give it a name.mp4", fps = 30, extra-args = ['vcodec', 'libx264'])
plt.show()
完整的错误消息如下所示

    Traceback (most recent call last):
  File "the_animation.py", line 71, in <module>
    plt.show()
  File "/usr/lib/pymodules/python2.7/matplotlib/pyplot.py", line 145,     in show
    _show(*args, **kw)
  File "/usr/lib/pymodules/python2.7/matplotlib/backend_bases.py",     line 117, in __call__
    self.mainloop()
  File     "/usr/lib/pymodules/python2.7/matplotlib/backends/backend_tkagg.py", line     69, in mainloop
    Tk.mainloop()
  File "/usr/lib/python2.7/lib-tk/Tkinter.py", line 366, in mainloop
    _default_root.tk.mainloop(n)
  File "/usr/lib/python2.7/lib-tk/Tkinter.py", line 1484, in __call__
    def __call__(self, *args):

这里的问题是在
动画
功能中,您多次使用
设置数据
,这与您认为的功能不同。当它是一个集合时,你就像一个附加一样使用它。参数应该是两个数组,分别包含该行的x和y值。这将为您的最小示例设置动画:

import numpy as np
from matplotlib import pyplot as plt
from matplotlib import animation

complex_vec = np.arange(5,6,.001)
real_vec = np.arange(7,8,.001)
time_vec = np.arange(0,1,.001)
num_files = np.size(time_vec)

#creating the modulus vector
modulus_vec = np.zeros(np.shape(complex_vec))
for k in range (0,complex_vec.size):
    a = complex_vec[k]
    b = real_vec[k]
    calc_modulus = np.sqrt(a**2 + b**2)
    modulus_vec[k] = calc_modulus

#finally animateing
fig = plt.figure()
ax = plt.axes(xlim = (-1,1) ,ylim = (-1,15))#limits were     arbitrary
#line = ax.plot([],[])
line, = ax.plot([], [], lw=2)

# initialization function: plot the background of each frame
def init():
    line.set_data([], [])
    return line,

def animate(i):
    x = time_vec[i]
    y = complex_vec[i]
    y1 = real_vec[i] 
    y2 = modulus_vec[i]
    # notice we are only calling set_data once, and bundling the y values into an array
    line.set_data(x,np.array([y, y1, y2]))
    return line,

animation_object = animation.FuncAnimation(fig, 
                                           animate, 
                                           init_func= init, 
                                           frames = num_files,
                                           interval = 30, 
                                           blit = True)

#turnn this line on to save as mp4
#anim.save("give it a name.mp4", fps = 30, extra-args = ['vcodec',     'libx264'])
plt.show()

您以前的尝试是设置xy值,然后用新的xy覆盖上一个值,然后再次执行此操作

你在哪一行收到你的标题上写的错误?这是更奇怪的部分,我将在短短几分钟内发布错误消息moment@Ioma你确定这就是全部错误?因为你的错误输出没有错误,你是对的,我支持,因为没有显示任何东西,我会得到一个错误,但这只是弹出的,所以我假设这是一个错误,但我猜不是,但是我现在真的很困惑,因为即使运行2小时,它仍然没有显示任何东西,只是图形窗口没有轴nothing@Ioma有吗如果是一个脚本,你可以发布或链接到这个文件,这算是一个最小的例子吗?如果没有可靠的错误输出或对文件的访问,则很难进行调试
import numpy as np
from matplotlib import pyplot as plt
from matplotlib import animation

complex_vec = np.arange(5,6,.001)
real_vec = np.arange(7,8,.001)
time_vec = np.arange(0,1,.001)
num_files = np.size(time_vec)

#creating the modulus vector
modulus_vec = np.zeros(np.shape(complex_vec))
for k in range (0,complex_vec.size):
    a = complex_vec[k]
    b = real_vec[k]
    calc_modulus = np.sqrt(a**2 + b**2)
    modulus_vec[k] = calc_modulus

#finally animateing
fig = plt.figure()
ax = plt.axes(xlim = (-1,1) ,ylim = (-1,15))#limits were     arbitrary
#line = ax.plot([],[])
line, = ax.plot([], [], lw=2)

# initialization function: plot the background of each frame
def init():
    line.set_data([], [])
    return line,

def animate(i):
    x = time_vec[i]
    y = complex_vec[i]
    y1 = real_vec[i] 
    y2 = modulus_vec[i]
    # notice we are only calling set_data once, and bundling the y values into an array
    line.set_data(x,np.array([y, y1, y2]))
    return line,

animation_object = animation.FuncAnimation(fig, 
                                           animate, 
                                           init_func= init, 
                                           frames = num_files,
                                           interval = 30, 
                                           blit = True)

#turnn this line on to save as mp4
#anim.save("give it a name.mp4", fps = 30, extra-args = ['vcodec',     'libx264'])
plt.show()