我目前正在评估不同的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) 查看matplotlib文档,似乎添加AxesSubplot到a 的标准方法Figure是使用Figure.add_subplot:
from matplotlib import pyplot
fig = pyplot.figure()
ax = fig.add_subplot(1,1,1)
ax.hist( some params .... )
Run Code Online (Sandbox Code Playgroud)
我希望能够AxesSubPlot独立于图形创建类似对象,因此我可以在不同的图中使用它们.就像是
fig = pyplot.figure()
histoA = some_axes_subplot_maker.hist( some params ..... )
histoA = some_axes_subplot_maker.hist( some other params ..... )
# make one figure with both plots
fig.add_subaxes(histo1, 211)
fig.add_subaxes(histo1, 212)
fig2 = pyplot.figure()
# make a figure with the first plot only
fig2.add_subaxes(histo1, 111)
Run Code Online (Sandbox Code Playgroud)
这是可能的matplotlib,如果可以,我该怎么做?
更新:我还没有设法解除Axes和Figures的创建,但是下面的答案中的示例可以很容易地在new或olf Figure实例中重用以前创建的轴.这可以通过一个简单的功能来说明:
def plot_axes(ax, fig=None, …Run Code Online (Sandbox Code Playgroud) 我想在4个轴上绘制图形,在每个轴上绘制前三个单独的绘图,最后在最后一个轴上绘制所有3个绘图.这是代码:
from numpy import *
from matplotlib.pyplot import *
fig=figure()
data=arange(0,10,0.01)
ax1=fig.add_subplot(2,2,1)
ax2=fig.add_subplot(2,2,2)
ax3=fig.add_subplot(2,2,3)
ax4=fig.add_subplot(2,2,4)
line1=ax1.plot(data,data)
line2=ax2.plot(data, data**2/10, ls='--', color='green')
line3=ax3.plot(data, np.sin(data), color='red')
#could I somehow use previous plots, instead recreating them all?
line4=ax4.plot(data,data)
line4=ax4.plot(data, data**2/10, ls='--', color='green')
line4=ax4.plot(data, np.sin(data), color='red')
show()
Run Code Online (Sandbox Code Playgroud)
结果图片是:
有没有办法首先定义图,然后将它们添加到轴,然后绘制它们?这是我心中的逻辑:
#this is just an example, implementation can be different
line1=plot(data, data)
line2=plot(data, data**2/10, ls='--', color='green')
line3=plot(data, np.sin(data), color='red')
line4=[line1, line2, line3]
Run Code Online (Sandbox Code Playgroud)
现在在ax1上绘制line1,在ax2上绘制line2,在ax3上绘制line3,在ax4上绘制line4.
每次我通过一个适合的程序,我试图刷新我在gui中的一些情节.此外,这些图是在可以调整大小的framw内,因此在调整大小后需要重新绘制轴和标签等.所以,想知道是否有人知道如何使用类似更新图的两侧plot.figure.canvas.copy_from_bbox和blit.这似乎只复制和blit图形区域的背景(绘制线条的位置),而不是图形或图形的边(标签和刻度线的位置).我一直试图让我的图表通过反复试验和读取mpl文档进行更新,但到目前为止,我的代码已经变得非常复杂,例如self.this_plot.canvas_of_plot..etc.etc.. .plot.figure.canvas.copy_from_bbox......这可能太复杂了.我知道我的语言可能有些偏差,但我一直在尝试阅读matplotlb文档,图,画布,图形,情节,图形等之间的差异开始躲避我.所以我的首要问题是:
1 - 如何更新matplotlib图周围的刻度和标签.
其次,既然我想更好地掌握这个问题的答案,
2 - 关于它们在GUI中覆盖的区域,绘图,图形,画布等之间有什么区别.
非常感谢你的帮助.