Plot 3 graphs 2 on top and one on bottom axis in python?

Question:

I am trying to plot 3 dendrograms, 2 on top and one on the bottom. But the only way I figured out in doing this:

fig, axes = plt.subplots(2, 2, figsize=(22, 14))
dn1 = hc.dendrogram(wardLink, ax=axes[0, 0])
dn2 = hc.dendrogram(singleLink, ax=axes[0, 1])
dn3 = hc.dendrogram(completeLink, ax=axes[1, 0])

Gives me a fourth blank graph on the bottom right. Is there a way to plot only 3 graphs?

Asked By: ArtemisCode7

||

Answers:

You can redivide the canvas area as you desire and use the 3rd argument to subplot to tell it which cell to plot to:

plt.subplot(2, 2, 1) # divide as 2x2, plot top left
plt.plt(...)

plt.subplot(2, 2, 2) # divide as 2x2, plot top right
plt.plt(...)

plt.subplot(2, 1, 2) # divide as 2x1, plot bottom
plt.plt(...)

You can also use a gridspec as follows:

gs = fig.add_gridspec(2, 2)
ax1 = fig.add_subplot(gs[0, 0])
ax2 = fig.add_subplot(gs[0, 1])
ax3 = fig.add_subplot(gs[1, :])

...
Answered By: MEE
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.