xarray–一维空间绘图学习记录

Simple Example

• dataarrays 最简单的画图方法就是调用`dataarray.plot()`
• xarray 可以通过使用坐标名称或者数据名称进行数据索引，如 `attrs.long_name, attrs.standard_name, DataArray.name and attrs.units` ，而这些名称可以通过`dataarray.attrs`命令获得，示例如下：
``````sst.attrs
``````
``````{'long_name': 'Monthly Mean of Sea Surface Temperature',
'unpacked_valid_range': array([-5., 40.], dtype=float32),
'actual_range': array([-1.7999996, 35.56862  ], dtype=float32),
'units': 'degC',
'precision': 2,
'var_desc': 'Sea Surface Temperature',
'dataset': 'NOAA Optimum Interpolation (OI) SST V2',
'level_desc': 'Surface',
'statistic': 'Mean',
'parent_stat': 'Weekly Mean',
'standard_name': 'sea_surface_temperature',
'cell_methods': 'time: mean (monthly from weekly values interpolated to daily)',
'valid_range': array([-500, 4000], dtype=int16)}
``````

``````sst1 =sst.isel(lat=10, lon=10)
sst1.plot()
``````

``````sst1[:200].plot.line("b-^")
``````

``````sst1[:200].plot.line(color="purple", marker="o")
``````

``````fig, axes = plt.subplots(ncols=2)

axes

air1d.plot(ax=axes[0])

air1d.plot.hist(ax=axes[1])

plt.tight_layout()

plt.draw()
``````

Controlling the figure size：控制图的大小

``````sst1.plot(aspect=2, size=3)

plt.tight_layout()
``````

Determine x-axis values

``````decimal_day = (sst1.time - sst1.time[0]) / pd.Timedelta("1d")

sst1_multi = sst1.assign_coords(decimal_day=("time", decimal_day.data))

sst1_multi
``````

``````sst1_multi.plot(x="decimal_day")
``````

``````sst1_multi = sst1_multi.set_index(date=("time", "decimal_day"))

sst1_multi.plot(x="decimal_day")
``````

``````sst1_multi = sst1_multi.drop("date")

sst1_multi.plot()
``````

Multiple lines showing variation along a dimension :多条线显示一个维度上的变化

``````sst.isel(lon=10, lat=[19, 21, 22]).plot.line(x="time")
``````

• 1 x：用于x轴的维度
• 2 hue（色调）：要用多条线表示的维度
因此，我们可以通过指定 `hue = lat`而不是 `x = ‘time`来绘制前面的图。如果需要，可以使用 `add _ legend = False` 关闭自动图例。或者，可以直接传递给 `xary.plot.line ()`: `sst.isel (lon = 10，lat = [19,21,22]).plot.line (hue ='lat')`

Dimension along y-axis :沿着y轴的维度

``````sst.isel(time=10, lon=[10, 11]).plot(y="lat", hue="lon")
``````

Step plots :步骤图

``````sst1[:20].plot.step(where="mid")
``````

``````sst_grp = sst.mean(["time", "lon"]).groupby_bins("lat", [0, 23.5, 66.5, 90])

sst_mean = sst_grp.mean()

sst_std = sst_grp.std()

sst_mean.plot.step()

(sst_mean + sst_std).plot.step(ls=":")

(sst_mean - sst_std).plot.step(ls=":")

plt.ylim(-20, 30)

plt.title("Zonal mean temperature")
``````

Other axes kwargs :其他关键字

``````sst.isel(time=10, lon=[10, 11]).plot.line( y="lat", hue="lon", xincrease=False, yincrease=False)
``````

THE END

)">