3

To arrange subplots in tables that can have colspans and rowspans the Pyplot-API of Matplotlib uses:

In this question user tcaswell says that one shouldn't mix the two API's:

Taking this advice in account, how is it possible to do colspans and rowspans without using the Pyplot-API?

Edit 1

I think it might be good to expand the question with a working example. I implement what user Julien recommended in his answer and everything works:

#!/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()
Community
  • 1
  • 1
tobias47n9e
  • 2,233
  • 3
  • 28
  • 54

1 Answers1

3

Part of the answer lies in the pyplot.subplot2grid documentation:

http://matplotlib.org/api/pyplot_api.html#matplotlib.pyplot.subplot2grid

Assuming you have defined a figure fig

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