【发布时间】:2021-09-20 12:43:43
【问题描述】:
如何使用 for 命令为每个情节添加颜色条和标题,就像这张图片reference_figure
import numpy as np
import matplotlib.pyplot as plt
import wradlib as wrl
import pyart
import xarray as xr
ds = xr.open_dataset('MDV-20180602-101927-PPIVol.nc')
def sweep(i):
si = ds.sweep_start_ray_index.values
ei = ds.sweep_end_ray_index.values
return slice(si[i],ei[i]+1)
i=0
x = ds.range * np.sin(np.deg2rad(ds.azimuth[sweep(i)]))
y = ds.range * np.cos(np.deg2rad(ds.azimuth[sweep(i)]))
fig, ax = plt.subplots(3, 2, figsize=(12, 15))
ax = ax.flatten()
variables = ['reflectivity',"velocity",'zdr','rhohv','phidp','spectral width']
ref = ax[0].pcolormesh(x/1e3, y/1e3, ds['DBZH'][sweep(i)].T, cmap='pyart_NWSRef')
vel = ax[1].pcolormesh(x/1e3, y/1e3, ds['VELH'][sweep(i)].T, cmap='pyart_NWSVel')
zdr = ax[2].pcolormesh(x/1e3, y/1e3, ds['ZDR'][sweep(i)].T, cmap='pyart_RefDiff', vmin=-1, vmax=8)
rho = ax[3].pcolormesh(x/1e3, y/1e3, ds['RHOHV'][sweep(i)].T, cmap='pyart_RefDiff', vmin=0.5, vmax=1.05)
phidp = ax[4].pcolormesh(x/1e3, y/1e3, ds['PHIDP'][sweep(i)].T, cmap='pyart_Wild25', vmin=-180, vmax=180)
width = ax[5].pcolormesh(x/1e3, y/1e3, ds['WIDTHH'][sweep(i)].T, cmap='pyart_NWS_SPW')
for myax in ax:
[myax.plot(k * np.cos(ds.azimuth[sweep(i)] * np.pi / 180),
k * np.sin(ds.azimuth[sweep(i)] * np.pi / 180), 'k-', linewidth=1, alpha=0.5) for k in [25,75,125]]
myax.set_aspect('equal')
fig.tight_layout()
plt.show()
输出是 Output
变量是应该使用的标题
【问题讨论】:
-
你试过 fig.colorbar 和 ax.set_title 吗?
标签: python numpy matplotlib python-xarray