简体   繁体   English

加速 Matplotlib

[英]Speeding up Matplotlib

Currently I am working on a real-time plot but the visualization is really slow.目前我正在处理实时绘图,但可视化非常慢。 I would like to know what things in general you can do to speed up things in Matplotlib:我想知道你可以做些什么来加速 Matplotlib 中的事情:

  • How does the backend affect the performance?后端如何影响性能? Are there backends that are better for real time plotting than others?是否有后端比其他后端更适合实时绘图?
  • Can I lower the resolution to increase FPS?我可以降低分辨率以提高 FPS 吗?
  • Why does the FPS of my plot increase if I reduce the window size?如果我减小窗口大小,为什么我的绘图的 FPS 会增加? Why does FPS drop dramatically if I switch to full screen mode?为什么切换到全屏模式后 FPS 会急剧下降?

I also tried to turn off everything I don't need:我还尝试关闭我不需要的一切:

ax.set_xticklabels(())
ax.set_yticklabels(())
ax.set_xticks([])
ax.set_yticks([])
ax.axis('off')
ax.get_xaxis().set_visible(False)
ax.get_yaxis().set_visible(False)

However, the effect is negligible.不过,效果微乎其微。 Are there more things I can turn off?还有更多我可以关闭的东西吗?

I would also like to know if it is possible to turn off the buttons (home button, etc.., see below) of the window that opens when creating a graph.我还想知道是否可以关闭创建图形时打开的窗口的按钮(主页按钮等,见下文)。 May turning off these buttons increase the speed?关闭这些按钮可以提高速度吗?

在此处输入图片说明

I also found that doing the following我还发现执行以下操作

fig.canvas.draw_idle()
fig.canvas.start_event_loop(1e-9)

is much slower for updating the plot than更新情节比更新情节慢得多

fig.canvas.draw_idle()
self.fig.canvas.update()
self.fig.canvas.flush_events()

Are there even better ways to update the objects in a plot?有没有更好的方法来更新图中的对象?

How does the backend affect the performance?后端如何影响性能? Are there backends that are better for real time plotting than others?是否有后端比其他后端更适合实时绘图?

The backend plays two roles: First, it renders everything, so the faster it renders, the faster the output.后端扮演两个角色:首先,它渲染所有内容,因此渲染得越快,输出就越快。 Second, the GUI toolkit used may play a role, because it may limit how fast an updated canvas is displayed.其次,所使用的 GUI 工具包可能会起作用,因为它可能会限制更新画布的显示速度。 It seems "Qt5Agg" is faster than "TkAgg" for example.例如,似乎"Qt5Agg""TkAgg"快。

Can I lower the resolution to increase FPS?我可以降低分辨率以提高 FPS 吗?

You can make the figure smaller, or use a smaller dpi.您可以缩小图形,或使用较小的 dpi。 Both will decrease the amount of pixels that need to be drawn and hence speed up drawing.两者都会减少需要绘制的像素数量,从而加快绘制速度。

Why does the FPS of my plot increase if I reduce the window size?如果我减小窗口大小,为什么我的绘图的 FPS 会增加? Why does FPS drop dramatically if I switch to full screen mode?为什么切换到全屏模式后 FPS 会急剧下降?

As above, more pixels that need to be drawn on screen mean slower rendering.如上所述,需要在屏幕上绘制的像素越多,渲染速度就越慢。

Are there more things I can turn off?还有更多我可以关闭的东西吗?

We don't know what you have in your code, so we can't know what to turn off.我们不知道您的代码中有什么,所以我们不知道要关闭什么。

May turning off these buttons increase the speed?关闭这些按钮可以提高速度吗?

No.不。


Finally, fig.canvas.draw_idle() in itself should be sufficient to update the plot, because usually you would have the event loop running already.最后, fig.canvas.draw_idle()本身应该足以更新绘图,因为通常您已经运行了事件循环。 Restarting an event loop is not helpful.重新启动事件循环没有帮助。

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

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