import numpy as np
import matplotlib.pyplot as plt
#import cartopy.crs as crs
#from cartopy.feature import NaturalEarthFeature
from netCDF4 import Dataset
from wrf import to_np, getvar, CoordPair, vertcross
# Open the NetCDF file
ncfile = Dataset("/home/mirantindri/python/WRFOUT/wrfout_d03_2020-08-09_03:00:00")
# Extract the model height and wind speed
p = getvar(ncfile, "pressure")
z = getvar(ncfile, "z")
wspd = getvar(ncfile, "uvmet_wspd_wdir", units="kt")[0,:]
dbz=getvar(ncfile, "dbz")
u=getvar(ncfile,"ua")
omega=getvar(ncfile,"omega")
# Create the start point and end point for the cross section
start_point = CoordPair(lat=36.618779, lon=124.0)
end_point = CoordPair(lat=37.0, lon=126.0)
# Compute the vertical cross-section interpolation. Also, include the
# lat/lon points along the cross-section.
u = vertcross(u, p, wrfin=ncfile, start_point=start_point,
end_point=end_point, latlon=True, meta=True)
omega = vertcross(omega, p, wrfin=ncfile, start_point=start_point,
end_point=end_point, latlon=True, meta=True)
# Create the figure
fig = plt.figure(figsize=(12,6))
ax = plt.axes()
# Make the contour plot
cont = ax.contour(to_np(u),levels=np.arange(-5,35,5,dtype=int),colors='black')
plt.clabel(cont, inline=1, fontsize=10,fmt='%d')
shade = ax.contourf(to_np(omega), cmap=get_cmap("jet"))
# Add the color bar
plt.colorbar(shade, ax=ax)
# Set the x-ticks to use latitude and longitude labels.
coord_pairs = to_np(u.coords["xy_loc"])
x_ticks = np.arange(coord_pairs.shape[0])
x_labels = [pair.latlon_str(fmt="{:.2f}, {:.2f}")
for pair in to_np(coord_pairs)]
ax.set_xticks(x_ticks[::20])
ax.set_xticklabels(x_labels[::20], rotation=45, fontsize=8)
# Set the y-ticks to be height.
vert_vals = to_np(u.coords["vertical"])
v_ticks = np.arange(vert_vals.shape[0])
ax.set_yticks(v_ticks[::15])
ax.set_yticklabels(vert_vals[::15],fontsize=8)
# Set the x-axis and y-axis labels
ax.set_xlabel("Latitude, Longitude", fontsize=12)
ax.set_ylabel("Pressure(mb)", fontsize=12)
plt.title("Vertical Cross Section of Wind Speed (kt)")
plt.savefig('/home/mirantindri/python/case20200822/VERTCROSS_WS_0822.png', dpi=500)
plt.show()
BUT now i want to edit my yticks labels like this, do you know how to make like that ?
thank you in advance..