matplotlib.pcolor 非常慢。替代品?
我想绘制一个 2D 数组(大约 1000x1000),其值对应于色标。所以我使用了 matplotlib.pcolor,它就是这样做的,但由于某种原因,当它到达这些尺寸时它非常慢(比如 2 分钟左右只是为了绘图)。这是什么原因呢?将 float 值转换为 int16 等会有帮助吗?有没有 pcolor 的替代品?
from pylab import *
data=genfromtxt('data.txt',autostrip=True, case_sensitive=True)
pcolor(data,cmap='hot')
colorbar()
show()
data.txt 包含数组。加载过程确实需要几秒钟,但主要的计算时间肯定是由 pcolor() 和 show() 函数使用的(大约各 60-90 秒)。
I want to plot a 2D array (roughly 1000x1000) with the values corresponding to a color scale. So I used matplotlib.pcolor, which did just that but for some reason it is super slow when it gets to those dimensions (like 2 minutes or so just to plot). What is the reason for that? Would converting the float values to int16 or so help? Are there any alternatives to pcolor?
from pylab import *
data=genfromtxt('data.txt',autostrip=True, case_sensitive=True)
pcolor(data,cmap='hot')
colorbar()
show()
data.txt is containing the array. The loading process does take a few seconds, but the main computing time is definitely used by BOTH the pcolor() and show() function (roughly maybe 60-90 secs each).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
作为未来谷歌用户的注释,还有
pcolormesh
和 < a href="http://matplotlib.org/api/axes_api.html#matplotlib.axes.Axes.pcolorfast">pcolorfast
。pcolormesh
的文档指出:imshow
应该更快,但灵活性稍差例如非直线轴。请参阅此页面,了解 <代码>pcolor、
pcolormesh
和imshow
。As a note for future googlers, there is also
pcolormesh
andpcolorfast
.The documentation for
pcolormesh
states that:imshow
should be even faster, but is a little less flexible with regards to e.g. non-rectilinear axes.See this page for a nice comparison between
pcolor
,pcolormesh
, andimshow
.imshow
会快得多。pcolor
返回一个 PolyCollection,对于一百万个元素来说它会相当慢,而 imshow 只是一个图像。请注意,pcolor 中的索引与 imshow 略有不同,但您可能不需要担心它,具体取决于您使用 pcolor 的方式。另外,通常当从 pcolor 转到 imshow 时,人们希望在 imshow 中设置 interpolation="nearest" (但对于如此大的图像,这可能也无关紧要)。
imshow
will be much faster.pcolor
returns a PolyCollection, which is going to be fairly slow with a million elements, whereas imshow is just an image.Note that the indexing in pcolor is slightly different than imshow, though you may not need to worry about it depending on how you used pcolor. Also, often when going from pcolor to imshow one wants to set
interpolation="nearest"
in imshow (but for such large images this may not matter either).