简体   繁体   English

情节循环真的很慢

[英]Plot looping really slow

I am writing a code to fit a gaussian over a function and if I don't plot the result (it is a datacube of ~60x60 spectra, so I am using a loop) the code works really fast. 我正在编写一个代码以在函数上拟合高斯,如果我没有绘制结果(它是~60x60光谱的数据立方体,所以我使用的是循环),代码工作得非常快。

But when I say the code to plot every graph it gets really slow, something like 2 graphs a second (when I don't plot it does like 40). 但是当我说每个图形绘制的代码变得非常慢时,就像2个图形一样(当我不绘制时它就像40个)。

Ok, I understand it can be right to slow a lot down, but there is a code in IDL that does the exact same thing and the code runs 8~10 plots per second. 好吧,我知道减慢速度可能是正确的,但IDL中有一个完全相同的代码,代码每秒运行8~10个图。

Is there a way to improve it? 有没有办法改善它? Or python is really slower than IDL? 或者python真的比IDL慢?

Here is the plot code: 这是情节代码:

plt.plot(wavelengthset, data_datacube[minpixel:maxpixel+1, j, i], 'k-', 
         wavelengthset, gaussian(fit[0], wavelengthset), 'r-')

plt.draw()

plt.clf()

I recommend looking into removing plt.draw() and using blit . 我建议考虑删除plt.draw()并使用blit If that's insufficient, please let me know a little more about your data and the purpose of the plots. 如果这还不够,请让我更多地了解您的数据和情节的目的。

See this answer for more info: why is plotting with Matplotlib so slow? 有关更多信息,请参阅此答案: 为什么使用Matplotlib进行绘图这么慢?

As the answer at the above link mentions, matplotlib is designed for quality, customizable, interactive plots. 正如上面链接提到的答案,matplotlib专为高质量,可定制的交互式绘图而设计。 Matplotlib may be slower than the data processing tools you're familiar with in IDL, but that's not to say that another, speed-conscious Python toolkit won't be just as fast/helpful. Matplotlib可能比你在IDL中熟悉的数据处理工具要慢,但这并不是说另一个速度敏感的Python工具包不会那么快/有用。

Good luck! 祝好运!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM