我想在我绘制的4个子图中添加一个颜色条。这是我尝试过的:
fig, ((ax1, ax2), (ax3,ax4)) = plt.subplots(nrows=2 , ncols=2, sharex=True)
axes = [ax1, ax2, ax3, ax4]
y_vals = [total_first_downs, touchdowns, possession, rushing_yards]
y_labels = ['Total First Downs','Touchdowns', 'Possession Time (seconds)', 'Total Rushing Yds']
colors = wins
for i in range(4):
axes[i].scatter(years, y_vals[i], c=colors, cmap='viridis')
axes[i].plot(years, y_vals[i], c='g', alpha=0.5)
axes[i].set_xticks(np.arange(2006,2020,2))
axes[i].set_ylabel(y_labels[i])
cbar = plt.colorbar()
cbar.set_label('Wins per Season')
plt.tight_layout()
plt.show()
我收到错误No mappable was found to use for colorbar creation. First define a mappable such as an image (with imshow) or a contour set (with contourf).
我试图研究类似的问题,但是找不到纠正此问题的方法。