Sometimes you want to show multiple charts in one figure but with different sizes. This helps highlight important data or save space.
0
0
Unequal subplot sizes in Matplotlib
Introduction
You want a big main chart and smaller side charts.
You need to compare one detailed plot with simpler summary plots.
You want to save space by making less important plots smaller.
You want to create a dashboard with charts of different sizes.
You want to control layout precisely for presentations or reports.
Syntax
Matplotlib
fig = plt.figure() ax1 = fig.add_axes([left, bottom, width1, height1]) ax2 = fig.add_axes([left2, bottom2, width2, height2])
The add_axes method takes a list of 4 numbers: [left, bottom, width, height].
All values are between 0 and 1 and represent the fraction of the figure size.
Examples
This creates one large plot on the left and a narrow plot on the right.
Matplotlib
fig = plt.figure() ax1 = fig.add_axes([0.1, 0.1, 0.7, 0.8]) # big plot ax2 = fig.add_axes([0.85, 0.1, 0.1, 0.8]) # narrow side plot
This creates one big plot on top and two smaller plots side by side below.
Matplotlib
fig = plt.figure() ax1 = fig.add_axes([0.1, 0.5, 0.8, 0.4]) # top plot ax2 = fig.add_axes([0.1, 0.1, 0.35, 0.3]) # bottom left ax3 = fig.add_axes([0.55, 0.1, 0.35, 0.3]) # bottom right
Sample Program
This code creates a figure with one large plot on the left and two smaller plots stacked on the right side. Each plot shows a different function.
Matplotlib
import matplotlib.pyplot as plt import numpy as np x = np.linspace(0, 10, 100) y1 = np.sin(x) y2 = np.cos(x) y3 = np.tan(x) / 10 # scaled down for visibility fig = plt.figure(figsize=(8, 5)) # Big main plot ax1 = fig.add_axes([0.1, 0.3, 0.6, 0.6]) ax1.plot(x, y1, label='sin(x)') ax1.set_title('Main Plot: sin(x)') ax1.legend() # Smaller side plot ax2 = fig.add_axes([0.75, 0.6, 0.2, 0.3]) ax2.plot(x, y2, 'r', label='cos(x)') ax2.set_title('Side Plot: cos(x)') ax2.legend() # Smaller bottom plot ax3 = fig.add_axes([0.75, 0.3, 0.2, 0.2]) ax3.plot(x, y3, 'g', label='tan(x)/10') ax3.set_title('Bottom Plot: tan(x)/10') ax3.legend() plt.show()
OutputSuccess
Important Notes
Use add_axes for precise control of subplot size and position.
Coordinates are fractions of the figure size, so 0.1 means 10% from the left or bottom.
Remember to adjust figsize for overall figure size to keep plots clear.
Summary
You can create subplots of different sizes using fig.add_axes().
Specify position and size as fractions of the figure with [left, bottom, width, height].
This helps highlight important plots or save space in your figure.