问题描述
我要在一个阵列中绘制约10,000个项目.它们具有大约1,000个唯一值.
I'm plotting about 10,000 items in an array. They are of around 1,000 unique values.
现在,绘图已经进行了半个小时.我确保其余代码可以正常工作.
The plotting has been running half an hour now. I made sure rest of the code works.
那慢吗?这是我第一次用pyplot绘制直方图.
Is it that slow? This is my first time plotting histograms with pyplot.
推荐答案
要使用matplotlib快速绘制直方图,您需要将histtype='step'
参数传递给pyplot.hist
.例如:
To plot histograms using matplotlib quickly you need to pass the histtype='step'
argument to pyplot.hist
. For example:
plt.hist(np.random.exponential(size=1000000,bins=10000))
plt.show()
平移或缩放大约需要15秒钟,而更新大约需要5-10秒钟.
takes ~15 seconds to draw and roughly 5-10 seconds to update when you pan or zoom.
相反,用histtype='step'
绘制:
plt.hist(np.random.exponential(size=1000000),bins=10000,histtype='step')
plt.show()
几乎立即进行绘图,可以立即进行平移和缩放.
plots almost immediately and can be panned and zoomed with no delay.
这篇关于Matplotlib.pyplot.hist()非常慢的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!