您好, 我尝试创建一个图形,其中一行有两个子图,旁边有一个颜色条。这是有效的,但我的问题是,我没有找到一种方法来创建两个相同的侧子图和一个细长的颜色条旁边。
我的第一次尝试是尝试:
import matplotlib.pyplot as plt
import numpy as np
X, Y = np.meshgrid([0.05, 0.1, 0.2, 0.3], [0,1,3,5])
fig, (ax1, ax2) = plt.subplots(figsize=(10,4), ncols = 2, sharey = True)
CS_18_14 = ax1.contour(X, Y, Bene_R18_14, levels, linewidths=2)
ax1.set_xlabel('level')
ax1.set_title('gross benefit 2')
ax1.set_ylabel('test')
CS_18_28 = ax2.contour(X, Y, Bene_R18_28, levels, linewidths=2, linestyles = '--')
ax2.set_xlabel('level')
ax2.set_title('gross benefit 2')
CB = plt.colorbar(CS_18_14, shrink=0.8)
plt.show()
第二个是:
fig = plt.figure(figsize=(10,4))
ax1 = plt.subplot2grid((1,13), (0,0), colspan = 6)
ax2 = plt.subplot2grid((1,13), (0,6), colspan = 6, adjustable='box-forced', sharex = ax1, sharey= ax1)
axCB = plt.subplot2grid((1,13), (0,12), colspan = 1)
CS_18_14 = ax1.contour(X, Y, Bene_R18_14, levels, linewidths=2)
ax1.set_xlabel('level')#r'proof load level in quantile of $\mu(R)$')
ax1.set_title('gross benefit 1'))
ax1.set_ylabel('test')
CS_18_28 = ax2.contour(X, Y, Bene_R18_28, levels, linewidths=2, linestyles = '--')
ax2.set_xlabel('level')
ax2.set_title('gross benefit 2')
CB = fig.colorbar(CS_18_14, cax = axCB)
plt.show()
如何获得与示例1中相当漂亮的颜色条,还有相同尺寸的子图?
干杯