python - 提高调整大小和平移 imshow/countourf/pcolormesh 的响应能力?
问题描述
我有以下内容:
import matplotlib.pyplot as plt
import numpy as np
fig, axes = plt.subplots(2, 4)
for ax in axes.ravel():
ax.imshow(np.random.rand(30, 30))
plt.show()
这很简单,但我发现在我的系统上调整图形大小非常慢(1-2 fps)。它只管理 8 个 30 x 30 阵列,所以我有点惊讶。我什至没有使用额外的功能调用和功能,如sharex=True
, sharey=True
, constrained_layout=True
, plt.colorbar()等,但即使禁用所有这些,上面的示例平移和缩放也非常缓慢。
有没有方便的方法来改善这一点?我正在尝试将这样的图形嵌入到 tk GUI 中,并且调整两者组合的大小是完全无法管理的。我使用pcolormesh和countourf得到了类似的结果,并尝试了设置interpolation='nearest'
选项。
即使是 blitting 示例在静态位置对我来说也很快刷新,所以我的问题与调整大小更一致,而不是数字的实际内容或数据量(我相信)。
import matplotlib.pyplot as plt
import numpy as np
import matplotlib.animation as animation
def gen(): return(np.random.rand(30, 30))
fig, axes = plt.subplots(2, 4, constrained_layout=True, sharex=True, sharey=True)
images = [ax.imshow(gen()) for ax in axes.ravel()]
def animate(i):
for im in images:
im.set_array(gen())
return(images)
anim = animation.FuncAnimation(fig, animate, interval=10, blit=True)
plt.show()
解决方案
推荐阅读
- azure - Azure 逻辑应用,队列中没有内容
- python - Django order_by 两个字段,第一个字段最后为空
- c++ - 在 GCC-7 中使用功能测试宏
- javascript - React:渲染大图像和放大
- javascript - Java Script Function 对于特定的正则表达式运行良好,但在另一个正则表达式中无法正常运行
- c# - 使用查找集合的 IValueConverter
- c# - Azure 函数 httpclient ObjectDisposedException 无法访问已处置的对象 SslStream
- excel - 无法工作簿。打开 XLS 文件类型?
- google-sheets - 如何创建一个公式来对一列中的值求和,但将这些值乘以另一列?
- c# - 如何将此解密合并到我的代码中,将散列密码转换回原始密码