Colorbar As A Subplot In Gridspec (python): Change Size
I have this gridspec subplot in python: It is a 3x3 Gridspec matrix of seaborn heatmaps with a single colorbar occupying the whole third column. I would like to make the colorbar
Solution 1:
You don't need to plot the colorbar in an extra subplot grid
I would recommend to look here: https://matplotlib.org/3.1.1/gallery/axes_grid1/demo_colorbar_with_inset_locator.html
You can plot the colorbar like:
fig = plt.figure(figsize=(6, 6))
grid = plt.GridSpec(4, 4, hspace=0, wspace=0)
main_ax = fig.add_subplot(grid[:-1, 1:])
y_hist = fig.add_subplot(grid[:-1, 0])
x_hist = fig.add_subplot(grid[-1, 1:]
im = main_ax.imshow(array, **kwags) # <- your plots here
y_hist.plot(x,y)
x_hist.plot(x,y)
axins = inset_axes(x_hist, # here using axis of the lowest plot
width="5%", # width = 5% of parent_bbox width
height="340%", # height : 340% good for a (4x4) Grid
loc='lower left',
bbox_to_anchor=(1.05, 0.3, 1, 1),
bbox_transform=x_hist.transAxes,
borderpad=0,
)
cb = fig.colorbar(im, cax=axins)
Post a Comment for "Colorbar As A Subplot In Gridspec (python): Change Size"