matplotlib.pcolor非常慢.备择方案? [英] matplotlib.pcolor very slow. alternatives?

查看:118
本文介绍了matplotlib.pcolor非常慢.备择方案?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想绘制一个2D数组(大约1000x1000),其值与色标相对应.因此,我使用了matplotlib.pcolor,它只是这样做了,但是由于某种原因,当达到这些尺寸时(例如绘制2分钟左右),它的速度非常慢.是什么原因呢?将float值转换为int16会有帮助吗?是否有pcolor的替代品?

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包含数组.加载过程确实需要花费几秒钟的时间,但是pcolor()和show()函数都肯定使用了主要的计算时间(大约每个60-90秒).

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).

推荐答案

imshow 将更快. pcolor返回PolyCollection,它将具有一百万个元素,运行起来相当慢,而imshow只是一幅图像.

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.

请注意,pcolor中的索引编制与imshow略有不同,尽管您可能不必担心它,具体取决于您使用pcolor的方式.另外,通常当从pcolor转到imshow时,人们希望在imshow中设置interpolation="nearest"(但是对于如此大的图像,这可能也没有关系).

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).

这篇关于matplotlib.pcolor非常慢.备择方案?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆