Python 2.7 我想拍《黑客帝国》电影,但是';AxeImage';对象是不可编辑的
这段代码是matplotlib =======Python 2.7 我想拍《黑客帝国》电影,但是';AxeImage';对象是不可编辑的,python-2.7,matplotlib,Python 2.7,Matplotlib,这段代码是matplotlib ======= import numpy as np import matplotlib.pyplot as plt import matplotlib.animation as animation fig2 = plt.figure() x = np.arange(-9, 10) y = np.arange(-9, 10).reshape(-1, 1) base = np.hypot(x, y) ims = [] for add in np.arange(3
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.animation as animation
fig2 = plt.figure()
x = np.arange(-9, 10)
y = np.arange(-9, 10).reshape(-1, 1)
base = np.hypot(x, y)
ims = []
for add in np.arange(30):
ims.append((plt.pcolor(x, y, base + add, norm=plt.Normalize(0, 50)),))
im_ani = animation.ArtistAnimation(fig2, ims, interval=50, repeat_delay=3000,
blit=True)
#im_ani.save('im.mp4', metadata={'artist':'Guido'})
im_ani.save('basic_example.gif', writer='imagemagick')
plt.show()
我想从plt.pcolor更改为plt.matshow,因为我必须将矩阵更改可视化
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.animation as animation
fig = plt.figure()
a = np.zeros(3)
b = np.identity(3)
a = np.matrix(a)
b = np.matrix(b)
ims = []
for i in np.arange(5):
w = a + i*b
w = w.tolist()
ims.append(plt.matshow(a + i*b))
ani = animation.ArtistAnimation(fig, ims)
plt.show()
错误消息如下:
TypeError
Traceback (most recent call last)
/Users/~/simple_anim_matrix.py in <module>()
152 ims.append(plt.matshow(a + i*b))
153
--> 154 ani = animation.ArtistAnimation(fig, ims)
155
156 #ani.save('demo4.mp4')
/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/matplotlib/animation.pyc in __init__(self, fig, artists, *args, **kwargs)
932 # over by the machinery.
933 self._framedata = artists
--> 934 TimedAnimation.__init__(self, fig, *args, **kwargs)
935
936 def _init_draw(self):
/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/matplotlib/animation.pyc in __init__(self, fig, interval, repeat_delay, repeat, event_source, *args, **kwargs)
876
877 Animation.__init__(self, fig, event_source=event_source,
--> 878 *args, **kwargs)
879
880 def _step(self, *args):
/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/matplotlib/animation.pyc in __init__(self, fig, event_source, blit)
557
558 # Clear the initial frame
--> 559 self._init_draw()
560
561 # Instead of starting the event source now, we connect to the figure's
/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/matplotlib/animation.pyc in _init_draw(self)
938 axes = []
939 for f in self.new_frame_seq():
--> 940 for artist in f:
941 artist.set_visible(False)
942 # Assemble a list of unique axes that need flushing
TypeError: 'AxesImage' object is not iterable
TypeError
回溯(最近一次呼叫最后一次)
/()中的Users/~/simple\u anim\u matrix.py
152 ims.追加(plt.matshow(a+i*b))
153
-->154 ani=动画。艺术形象(图,ims)
155
156#ani.save('demo4.mp4')
/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/Python/matplotlib/animation.pyc在__init__;中(self、fig、artists、*args、**kwargs)
机器旁边。
933 self.\u framedata=艺术家
-->934时间信息。_初始__(self,fig,*args,**kwargs)
935
936定义初始绘图(自):
/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/Python/matplotlib/animation.pyc in_uuuuuuinit_uuuuuuuu(self、fig、interval、repeat_delay、repeat、event_source、*args、**kwargs)
876
877动画。_初始__(self,fig,event_source=event_source,
-->878*args,**kwargs)
879
880 def_步骤(自,*参数):
/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/Python/matplotlib/animation.pyc in_uuuuinit_uuu(self,fig,event_source,blit)
557
558#清除初始帧
-->559自绘制()
560
561#我们现在不启动事件源,而是连接到图的
/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/Python/matplotlib/animation.pyc in_init_draw(self)
938轴=[]
939用于f在自身中。新的_框架_seq():
-->940对于f中的艺术家:
941艺术家。设置为可见(假)
942#列出需要冲洗的独特轴
TypeError:“AxeImage”对象不可编辑
如果你能更具体地说明你到底想做什么(从功能的角度来看),以及在哪一行代码上引发异常,人们会更容易帮助你。从你包含的工作示例来看,我想说,ims.append(plt.matshow(a+I*b))
这一行是错误的。您需要将matshow
的输出放在一个iterable(列表,或示例中的元组):ims.append((plt.matshow(a+i*b))
如果您能更具体地说明您正试图做什么(从功能角度),人们会更容易帮助您,以及在哪一行代码上抛出异常。从您包含的工作示例来看,我认为行ims.append(plt.matshow(a+I*b))
是错误的。您需要将matshow
的输出放在一个iterable(列表或元组,如示例所示):ims.append((plt.matshow(a+i*b)))