栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

subplot2grid中的条形图

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

subplot2grid中的条形图

错误来自线路

return im1, im2, rects

在工作解决方案中,您有

returnrects
,即您返回具有
set_animated
方法的艺术家列表。在失败的代码中,您将拥有一个BarContainer和两个艺术家的元组。如错误所示,
AttributeError:’BarContainer’对象没有属性’set_animated’

一个解决方案可能是生成BarContainer的内容列表,您可以将其连接到其他两位艺术家。

return [rect for rect in rects]+[im1, im2]

一个完整的工作示例:

import matplotlib.pyplot as pltimport matplotlib.animation as animationres_x, res_y = [1,2,3], [1,2,3]fig = plt.figure()ax = plt.subplot2grid((2, 2), (0, 0), rowspan=2)ax2 = plt.subplot2grid((2, 2), (0, 1))ax3 = plt.subplot2grid((2,2), (1,1))rects = ax3.bar(res_x, res_y, color='b')im1 = ax.imshow([[1,2],[2,3]], vmin=0)im2 = ax2.imshow([[1,2],[2,3]], vmin=0)def animate(i):    im1.set_data([[1,2],[(i/100.),3]])    im2.set_data([[(i/100.),2],[2.4,3]])    for rect, yi in zip(rects, range(len(res_x))):        rect.set_height((i/100.)*(yi+0.2))    return [rect for rect in rects]+[im1, im2]anim = animation.FuncAnimation(fig, animate, frames=200, interval=20, blit=True)plt.show()


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/660259.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号