matplotlib.pyplot和matplotlib.figure有什么区别?

lam*_*mba 12 python wxpython matplotlib

我刚进入matplotlib.

我看到的一些例子matplotlib.pyplot使用,但与wxPython的整合matplotlib时,我经常看到matplotlib.figure

from matplotlib.figure import Figure

...

vboxFigure = wx.BoxSizer(wx.VERTICAL)
self.figure = Figure()
self.axes = self.figure.add_subplot(111)

t = [1,2,3,4,5]
s = [0,0,0,0,0]

self.axes.plot(t,s, 'b-')
self.canvas = FigureCanvas(panel, -1, self.figure)

vboxFigure.Add(self.canvas, 1, wx.LEFT | wx.TOP | wx.EXPAND)
hbox.Add(vboxFigure, 1, flag=wx.EXPAND)
Run Code Online (Sandbox Code Playgroud)

使用matplotlib.figure和绘图有什么区别matplotlib.pyplot?可以matplotlib.pyplot用于构建一个wx应用程序吗?

Jou*_*nen 12

Pyplot是类似Matlab的状态机API,matplotlib.figure.Figure是面向对象API的一部分.请参阅本教程以开始使用面向对象的API.如果您想创建一个wx应用程序,您很可能需要学习OO API.

  • 由于该教程的原始链接已被破坏,我将其修复为指向web.archive.org上的最后一个快照 (5认同)