相关疑难解决方法(0)

为什么用Matplotlib绘图这么慢?

我目前正在评估不同的python绘图库.现在我正在尝试使用matplotlib,我对性能非常失望.以下示例是从SciPy示例中修改的,并且每秒仅给出~8帧!

有什么方法可以加快速度,或者我应该选择不同的绘图库?

from pylab import *
import time

ion()
fig = figure()
ax1 = fig.add_subplot(611)
ax2 = fig.add_subplot(612)
ax3 = fig.add_subplot(613)
ax4 = fig.add_subplot(614)
ax5 = fig.add_subplot(615)
ax6 = fig.add_subplot(616)

x = arange(0,2*pi,0.01)
y = sin(x)
line1, = ax1.plot(x, y, 'r-')
line2, = ax2.plot(x, y, 'g-')
line3, = ax3.plot(x, y, 'y-')
line4, = ax4.plot(x, y, 'm-')
line5, = ax5.plot(x, y, 'k-')
line6, = ax6.plot(x, y, 'p-')

# turn off interactive plotting - speeds things up by 1 Frame …
Run Code Online (Sandbox Code Playgroud)

python matplotlib

85
推荐指数
4
解决办法
10万
查看次数

Matplotlib 动画太慢(~3 fps)

我需要对数据进行动画处理,因为它们带有 2D histogram2d(也许以后是 3D,但我听说 mayavi 更适合)。

这是代码:

import numpy as np
import numpy.random
import matplotlib.pyplot as plt
import time, matplotlib


plt.ion()

# Generate some test data
x = np.random.randn(50)
y = np.random.randn(50)

heatmap, xedges, yedges = np.histogram2d(x, y, bins=5)
extent = [xedges[0], xedges[-1], yedges[0], yedges[-1]]

# start counting for FPS
tstart = time.time()

for i in range(10):

    x = np.random.randn(50)
    y = np.random.randn(50)

    heatmap, xedges, yedges = np.histogram2d(x, y, bins=5)

    plt.clf()
    plt.imshow(heatmap, extent=extent)
    plt.draw()

# calculate and print FPS
print …
Run Code Online (Sandbox Code Playgroud)

python matplotlib

3
推荐指数
1
解决办法
2万
查看次数

标签 统计

matplotlib ×2

python ×2