首页 > 解决方案 > 如何使用 Gridspec 为我的所有子图绘制一个颜色条?

问题描述

我正在尝试为我拥有的所有子批次绘制一个颜色条(范围:0,最大值)。我在这里尝试了Matplotlib 2 Subplots, 1 Colorbar的解决方案,但它们需要使用我没有使用的 plt.subplots。

这是我当前的代码,它显示 3 个单独的颜色条。

fig = plt.figure(figsize=(15,15))
G = gridspec.GridSpec(2, 2)


#Haut
top = plt.subplot(G[0,0], projection='polar')
phi2D_grid, rho2D_grid = np.meshgrid(phi_grid, rho_grid)
plt.pcolormesh(phi2D_grid, rho2D_grid, compteur_top, cmap='jet', vmin=0, vmax=max)
plt.colorbar()

#Côtés
lat = plt.subplot(G[1,:])
phi2D_grid, z2D_grid = np.meshgrid(phi_grid, z_grid)
plt.pcolormesh(phi2D_grid, z2D_grid, compteur_lat, cmap='jet', vmin=0, vmax=max)
 plt.colorbar()


#Bas
bot = plt.subplot(G[0, 1], projection='polar')
phi2D_grid, rho2D_grid = np.meshgrid(phi_grid, rho_grid)
plt.pcolormesh(phi2D_grid, rho2D_grid, compteur_bot, cmap='jet', vmin=0, vmax=max)
plt.colorbar()

我想我确实需要在这里使用 Gridspec ,因为我需要按如下方式显示我的数字:

3 个图表

标签: pythonmatplotlibcolorbar

解决方案


推荐阅读