Chica_Programmador
Chica_Programmador

Reputation: 137

adjusting subplot with a colorbar

I have made the following visualization. enter image description here I am at loss to figure out how to adjust the size of the third subplot according to the other two (they are sharing the x-axis). The properties that are given here are not helping much and the examples I found on SO also seem to be addressing cases different from mine. Can anyone please help?

Upvotes: 1

Views: 1214

Answers (1)

ImportanceOfBeingErnest
ImportanceOfBeingErnest

Reputation: 339220

An easy method would be to add another two colorbars but make them invisible.

import matplotlib.pyplot as plt

fig, (ax,ax2,ax3) = plt.subplots(3,1, sharex=True)
ax.plot([1,3,5],[1,2,5])
ax2.plot([3,5,9],[4,2,2])
ax3.plot([5,7,12],[1,5,3])

sm = plt.cm.ScalarMappable()
sm.set_array([])
fig.colorbar(sm, ax=ax3)

# add two more colorbars, but make them invisible
fig.colorbar(sm, ax=ax2).ax.set_visible(False)
fig.colorbar(sm, ax=ax).ax.set_visible(False)

plt.subplots_adjust(right=1)
plt.show()

enter image description here

Upvotes: 2

Related Questions