Python matplotlib子地块内的多色线图

Python matplotlib子地块内的多色线图,python,matplotlib,Python,Matplotlib,我目前正在使用matplotlib图和子图来绘制一些曲率计数直方图和它们所属的轮廓 我希望将这些等高线绘制为多色线,局部曲率作为颜色条件 我现在的代码是: fig = plt.figure() fig.tight_layout() gs1 = fig.add_gridspec(nrows=2, ncols=3) fig_ax1 = fig.add_subplot(gs1[0, 0]) fig_ax1.title.set_text('timestep = 0') fig_ax1.hist(cur

我目前正在使用matplotlib图和子图来绘制一些曲率计数直方图和它们所属的轮廓

我希望将这些等高线绘制为多色线,局部曲率作为颜色条件

我现在的代码是:

fig = plt.figure()
fig.tight_layout()
gs1 = fig.add_gridspec(nrows=2, ncols=3)

fig_ax1 = fig.add_subplot(gs1[0, 0])
fig_ax1.title.set_text('timestep = 0')
fig_ax1.hist(curvature0, weights=np.ones(len(curvature0)) / len(curvature0), bins=20)

fig_ax2 = fig.add_subplot(gs1[0, 1])
fig_ax2.title.set_text('timestep = 40')
fig_ax2.hist(curvature10, weights=np.ones(len(curvature10)) / len(curvature10), bins=20)

fig_ax3 = fig.add_subplot(gs1[0, 2])
fig_ax3.title.set_text('timestep = 120')
fig_ax3.hist(curvature18, weights=np.ones(len(curvature18)) / len(curvature18), bins=20)

fig_ax4 = fig.add_subplot(gs1[1, 0])
fig_ax4.plot(xcoordinates[0], ycoordinates[0])

fig_ax5 = fig.add_subplot(gs1[1, 1])
fig_ax5.plot(xcoordinates[10], ycoordinates[10])

fig_ax6 = fig.add_subplot(gs1[1, 2])
fig_ax6.plot(xcoordinates[18], ycoordinates[10])
plt.show()
输出下图:

我尝试在这里实现matplotlib示例:

他们创建了一个新的子批和axs,这一事实让我很为难。我不知道如何在当前用于子地块的网格中执行此操作


任何关于如何制作此图的提示都将不胜感激

链接的示例绘制在子地块
axs[0]
上,而您绘制在
图ax4
上。用
图ax4
替换
axs[0]
应该很简单。@JohanC我试过了,但它没有画任何图形,只画了空的子图。我是否会完全跳过
fig,axs=plt.子批(2,1,sharex=True,sharey=True)
行?如果不再创建fig,我需要在上面画什么颜色条呢?在你的例子中,
fig
ax
来自
plt.figure()
fig.add_subplot(…)
,所以你不应该使用
plt.subplot()
。您仍然可以使用
fig.colorbar(…,ax=fig\u ax4)