Python 带无量纲坐标的Xarray plot.line
我希望使用无量纲坐标而不是量纲坐标绘制一系列直线图 在pcolormesh中可以:Python 带无量纲坐标的Xarray plot.line,python,python-xarray,Python,Python Xarray,我希望使用无量纲坐标而不是量纲坐标绘制一系列直线图 在pcolormesh中可以: import xarray as xr import numpy as np import matplotlib.pyplot as plt # Setup data array, from http://xarray.pydata.org/en/stable/plotting.html#multidimensional-coordinates lon, lat = np.meshgrid(np.linspac
import xarray as xr
import numpy as np
import matplotlib.pyplot as plt
# Setup data array, from http://xarray.pydata.org/en/stable/plotting.html#multidimensional-coordinates
lon, lat = np.meshgrid(np.linspace(-20, 20, 5),
np.linspace(0, 30, 4))
lon += lat/10
lat += lon/10
da = xr.DataArray(np.arange(20).reshape(4, 5), dims=['y','x'],
coords = {'lat': (('y', 'x'), lat),
'lon': (('y', 'x'), lon)})
# plot in terms of y,x, the dimensional coordinate
fig,ax = plt.subplots()
da.plot.pcolormesh('y','x')
# plot in terms of lon, lat, the non-dimensional coordinate
fig, ax = plt.subplots()
da.plot.pcolormesh('lon', 'lat')
# plot lines in terms of x,y, the dimensional coordinate
fig, ax = plt.subplots()
da.plot.line(x='x')
# plot lines in terms of lon, lat?
da.plot.line(x='lon') #gives error
基本上,我想通过二维数据绘制直线切割
我可以用基本的matplotlib(如下)来做,但我想要一个1行的xarray
fig,ax = plt.subplots()
for i in range(int(da.y.shape[0])):
ax.plot(da.lon[i], da[i])
我不确定为什么DataArray.plot.line不允许非维度坐标。您应该以电子邮件的形式提交此文件 对于单行程序解决方案,可以省略for循环,如下所示:
ax.plot(da.lon.T, da.data.T)