我用matplotlib.pyplot
做了一个contourf
图。现在我想在y = 0
处有一条带条件着色的水平线(或者类似ax.vspan
的东西也可以)。我会告诉你我有什么和我想得到什么。我想用一个数组来实现这一点,比如说landsurface
,它表示陆地、海洋或冰。这个数组充满了1
(陆地)、2
(海洋)或3
(冰),并且有len(locs)
(因此x轴)。你知道吗
这是绘图代码:
plt.figure()
ax=plt.axes()
clev=np.arange(0.,50.,.5)
plt.contourf(locs,height-surfaceheight,var,clev,extend='max')
plt.xlabel('Location')
plt.ylabel('Height above ground level [m]')
cbar = plt.colorbar()
cbar.ax.set_ylabel('o3 mixing ratio [ppb]')
plt.show()
到目前为止,我的情况是:
这就是我想要的:
非常感谢!你知道吗
我建议添加一个
imshow()
和适当的extent
,例如:收益率:
简介
我要用line collection。你知道吗
因为我没有你的原始数据,我伪造了一些数据,使用一个简单的正弦曲线和绘制在基线上的颜色代码对应的小,中,高值的曲线
代码
通常,我们需要显式导入
LineCollection
只是画一些东西,正弦曲线(xr
从曲线值(对应于曲面类型)到
LineCollection
颜色的颜色编码,请注意LineCollection
要求将颜色指定为RGBA元组,但是我看到了使用颜色字符串的示例,呸!你知道吗在一个行集合中,我们需要一个段序列,这里我决定把我的编码行放在
y=0
,但你只需给s
加一个常量,就可以上下移动它。我承认形成片段序列有点棘手。。。你知道吗
最后,我们把一切都放在画布上
相关问题 更多 >
编程相关推荐