如何向子绘图添加颜色栏和标题?

oaxa6hgo  于 2021-08-20  发布在  Java
关注(0)|答案(0)|浏览(205)

如何使用for命令为每个绘图添加颜色栏和标题,如图所示

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()

输出就是输出
变量是应该使用的标题

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题