2

I would like to make a figure which looks like the image below. I have seen one post which did something similar with subplot (shown below) but I cannot adapt it to this specific design.

Help would be much appreciated. Thank you.

plt.figure(figsize=(12, 6))
ax1 = plt.subplot(2,3,1)
ax2 = plt.subplot(2,3,2)
ax3 = plt.subplot(2,3,3)
ax4 = plt.subplot(2,1,2)
axes = [ax1, ax2, ax3, ax4]

Layout of figure

  • 1
    See this. [https://matplotlib.org/stable/gallery/subplots_axes_and_figures/gridspec_multicolumn.html](https://matplotlib.org/stable/gallery/subplots_axes_and_figures/gridspec_multicolumn.html) – r-beginners Mar 11 '22 at 13:54

1 Answers1

1

From the documentation:

import matplotlib.pyplot as plt
from matplotlib.gridspec import GridSpec


def format_axes(fig):
    for i, ax in enumerate(fig.axes):
        ax.text(0.5, 0.5, "ax%d" % (i+1), va="center", ha="center")
        ax.tick_params(labelbottom=False, labelleft=False)

fig = plt.figure(constrained_layout=True)

gs = GridSpec(2, 3, figure=fig)
ax1 = fig.add_subplot(gs[0, 0])
ax2 = fig.add_subplot(gs[1, 0])
ax3 = fig.add_subplot(gs[:, 1])
ax4 = fig.add_subplot(gs[:, 2])

fig.suptitle("GridSpec")
format_axes(fig)

plt.show()

enter image description here

Corralien
  • 109,409
  • 8
  • 28
  • 52