【发布时间】:2018-01-10 11:09:48
【问题描述】:
我正在尝试使用 xarray 在可变网格上绘制数据。存储我的数据的网格会随着时间而变化,但会保持相同的尺寸。
我希望能够在给定时间绘制它的 1d 切片。我正在尝试做的一个玩具示例如下所示。
import xarray as xr
import numpy as np
import matplotlib.pyplot as plt
time = [0.1, 0.2] # i.e. time in seconds
# a 1d grid changes over time, but keeps the same dims
radius = np.array([np.arange(3),
np.arange(3)*1.2])
velocity = np.sin(radius) # make some random velocity field
ds = xr.Dataset({'velocity': (['time', 'radius'], velocity)},
coords={'r': (['time','radius'], radius),
'time': time})
如果我尝试在不同的时间绘制它,即
ds.sel(time=0.1)['velocity'].plot()
ds.sel(time=0.2)['velocity'].plot()
plt.show()
但我希望它能够复制我可以明确使用的行为 matplotlib。在这里,它正确地绘制了当时的速度与半径的关系。
plt.plot(radius[0], velocity[0])
plt.plot(radius[1], velocity[1])
plt.show()
我可能使用了错误的 xarray,但它应该根据当时的适当半径值绘制速度。
我是否设置了错误的数据集或使用了错误的绘图/索引功能?
【问题讨论】:
标签: python matplotlib python-xarray