Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to create a figure where one axis is placed between and under 2 alligned axes?

I want to create a figure with the layout seen in the image below. Ideally, all the axes must have same dimensions (sorry my paint skills are not very good).

enter image description here

I have found the following tutorial: https://matplotlib.org/stable/tutorials/intermediate/arranging_axes.html, but the solutions seem very complicated. I was wondering if there is an easier way to do this. Thanks in advance.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Arguably the easiest way to achieve that is by using GridSpec:

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

gs = GridSpec(3, 4)
fig = plt.figure(tight_layout=True)
ax1 = fig.add_subplot(gs[0, :2])
ax2 = fig.add_subplot(gs[0, 2:])
ax3 = fig.add_subplot(gs[1, :2])
ax4 = fig.add_subplot(gs[1, 2:])
ax5 = fig.add_subplot(gs[2, 1:-1])

enter image description here

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading