Matplotlib:Gridspec或plt.subplot2grid的OOP等价物是什么

Matplotlib:Gridspec或plt.subplot2grid的OOP等价物是什么,matplotlib,Matplotlib,要在可以具有colspan和rowspans的表中排列子地块,Matplotlib的Pyplot API使用: 在这个问题上,用户tcaswell说不应该混合使用这两种API: 考虑到这个建议,如何在不使用Pyplot API的情况下实现colspan和rowspans 编辑1 我认为用一个工作示例来扩展这个问题可能会很好。我实现了用户Julien在回答中的建议,一切正常: #!/usr/bin/python3 from gi.repository import Gtk from

要在可以具有colspan和rowspans的表中排列子地块,Matplotlib的Pyplot API使用:

在这个问题上,用户tcaswell说不应该混合使用这两种API:

考虑到这个建议,如何在不使用Pyplot API的情况下实现colspan和rowspans

编辑1 我认为用一个工作示例来扩展这个问题可能会很好。我实现了用户Julien在回答中的建议,一切正常:

#!/usr/bin/python3

from gi.repository import Gtk
from matplotlib.backends.backend_gtk3cairo import (FigureCanvasGTK3Cairo
    as FigureCanvas)
from matplotlib.backends.backend_gtk3 import (NavigationToolbar2GTK3 
    as NavigationToolbar)
import mplstereonet
from matplotlib.gridspec import GridSpec
from matplotlib.figure import Figure

class MyWindow(Gtk.Window):
    def __init__(self):
        Gtk.Window.__init__(self)
        self.set_size_request(500, 500)
        self.box = Gtk.Box(orientation=Gtk.Orientation.VERTICAL, spacing=6)
        self.add(self.box)

        self.fig = Figure(dpi = 80)
        gridspec = GridSpec(3, 3)

        subplot_one = gridspec.new_subplotspec((0, 0),
                                            rowspan = 1, colspan = 3)
        subplot_two = gridspec.new_subplotspec((1, 0), rowspan = 2,
                                            colspan = 1)
        subplot_three = gridspec.new_subplotspec((1, 1), rowspan = 2,
                                            colspan = 2)

        ax_one = self.fig.add_subplot(subplot_one)
        ax_two = self.fig.add_subplot(subplot_two)
        ax_three = self.fig.add_subplot(subplot_three)

        xdata = [0.5, 0.2, 0.7, 0.3]
        ydata = [0.2, 0.8, 0.2, 0.4]

        ax_one.scatter(xdata, ydata)
        ax_two.scatter(xdata, ydata)
        ax_three.scatter(xdata, ydata)

        self.canvas = FigureCanvas(self.fig)
        self.box.pack_start(self.canvas, True, True, 0)

win = MyWindow()
win.connect("delete-event", Gtk.main_quit)
win.show_all()
Gtk.main()

部分答案在
pyplot.subplot2grid
文档中:

假设您已经定义了一个图
fig

from matplotlib.gridspec import GridSpec
gridspec = GridSpec(nrows, ncols)
subplotspec = gridspec.new_subplotspec((row, col), rowspan, colspan)
ax = fig.add_subplot(subplotspec)

谢谢你的解释。这无疑使我更进一步。您可能知道如何将轴和绘图添加到示例中吗?如何
ax=fig.add_subplot(subplotspec)
然后
ax.plot()
?谢谢。我误解了轴心返回的位置。你让我开心!用户tcaswell实际上是matplotlib的作者。。。