在xarray中将线图添加到FaceGrid

2024-10-01 07:23:32 发布

您现在位置:Python中文网/ 问答频道 /正文

我通过xarray将二维时间序列绘制为FaceGrid

p = gmt.plot.line(x='time', add_legend=False, alpha = 0.1, color = ('k'), ylim = (-1, 1.2), col='MCrun', col_wrap = 5)

enter image description here 我想添加另一个在顶部具有相同轴和尺寸的线图。对于个人成员,这只是:

gmt.isel(MCrun=0).plot.line(x='time', add_legend=False, alpha = 0.1, color = 'k', ylim = (-3, 1.2))
gmt_esmean.isel(MCrun=0).plot.line(x='time', add_legend=False, color = 'red')

enter image description here

但是使用相同的两个平面网格可以得到20个图——10个是单独的线,10个是平均值。最近的一次是

def smean_plot(*args, **kwargs):
    gmt_esmean.plot.line(x='time', add_legend=False, color = 'red')

p = gmt.plot.line(x='time', add_legend=False, alpha = 0.1, color = ('k'), ylim = (-1, 1.2), col='MCrun', col_wrap = 5)
p.map(smean_plot)

“全部”是指在所有打印中添加不需要的轴标题。 enter image description here

任何关于如何仅将平均值添加到相应集合的想法都将受到极大的赞赏


Tags: alphaaddfalsetimeplotlinecolcolor
1条回答
网友
1楼 · 发布于 2024-10-01 07:23:32

好的,我喜欢的一种方法是通过循环中的子图一个接一个地绘制图形。将x轴和y轴设置为共享,并减少图形边距。它并不像我希望的那样优雅,但效果很好

fig, axs = plt.subplots(ncols=5, nrows=2, figsize=(18,6), sharex=True, sharey=True, gridspec_kw={'hspace': 0.2, 'wspace': 0.1})
axs = axs.ravel()
for i in range(10):
        gmt.isel(MCrun=i).plot.line(ax = axs[i], x='time', add_legend=False, alpha = 0.1, color = ('k'), ylim = (-1.2, 0.8))
        gmt_esmean.isel(MCrun=i).plot.line(ax = axs[i], x='time', add_legend=False, color = 'red')+ 1
plt.draw()

enter image description here

相关问题 更多 >