【发布时间】:2018-09-06 02:11:57
【问题描述】:
我希望使用无量纲坐标而不是量纲坐标绘制一系列线图。
在 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.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
plot in terms of y,x, the dimensional coordinate
plot in terms of lon, lat, the non-dimensional coordinate
plot lines in terms of x,y, the dimensional coordinate
基本上,我想绘制穿过 2D 数据的线。
我可以使用基本的 matplotlib(如下)来做到这一点,但我想要 xarray 中的 1 行。
fig,ax = plt.subplots()
for i in range(int(da.y.shape[0])):
ax.plot(da.lon[i], da[i])
【问题讨论】:
标签: python python-xarray