Skip to content

Subplots and Figure Size

Subplots

2x2 subplots
import matplotlib.pyplot as plt
 
fig, axes = plt.subplots(2, 2, figsize=(10, 6))
 
axes[0, 0].plot([1, 2, 3], [1, 4, 9])
axes[0, 0].set_title("Line")
 
axes[0, 1].bar(["A", "B", "C"], [5, 2, 7])
axes[0, 1].set_title("Bar")
 
axes[1, 0].hist([1, 1, 2, 2, 2, 3, 4], bins=4, edgecolor="black")
axes[1, 0].set_title("Histogram")
 
axes[1, 1].scatter([1, 2, 3, 4], [10, 11, 9, 12])
axes[1, 1].set_title("Scatter")
 
fig.suptitle("Mini dashboard")
plt.tight_layout()
plt.show()
2x2 subplots
import matplotlib.pyplot as plt
 
fig, axes = plt.subplots(2, 2, figsize=(10, 6))
 
axes[0, 0].plot([1, 2, 3], [1, 4, 9])
axes[0, 0].set_title("Line")
 
axes[0, 1].bar(["A", "B", "C"], [5, 2, 7])
axes[0, 1].set_title("Bar")
 
axes[1, 0].hist([1, 1, 2, 2, 2, 3, 4], bins=4, edgecolor="black")
axes[1, 0].set_title("Histogram")
 
axes[1, 1].scatter([1, 2, 3, 4], [10, 11, 9, 12])
axes[1, 1].set_title("Scatter")
 
fig.suptitle("Mini dashboard")
plt.tight_layout()
plt.show()

Figure size rules

  • Use larger figures for long labels and multiple subplots.
  • Smaller is fine for single simple plots.

Tip

plt.tight_layout()plt.tight_layout() prevents label overlaps in most cases.

If this helped you, consider buying me a coffee ☕

Buy me a coffee

Was this page helpful?

Let us know how we did