How to set x,ylabel in cartopy for WRF output

15 Views Asked by At

I want to set x,ylabel like uploaded figure. bottom x-axis means latitude, left y-axis means longitude. enter image description here but my figure : right y-axis means longitude. I want to display longitude only left y-axis and display latitude on only bottom x-axis. Please check my code and correct.[text](enter image description here)

from netCDF4 import Dataset
import matplotlib.pyplot as plt
import matplotlib.cm as cm
import cartopy.crs as ccrs
import numpy as np
from cartopy.feature import NaturalEarthFeature
import matplotlib
import matplotlib.ticker as mticker
from cartopy.mpl.ticker import (LongitudeFormatter,LatitudeFormatter, LatitudeLocator)
from wrf import (to_np, getvar, smooth2d, get_cartopy, cartopy_xlim,
                 cartopy_ylim, latlon_coords)

ncfile = Dataset("D:/output/wrfout_d01_2021-08-07_18_00_00")

T2 = getvar(ncfile, "T2")
T2_C = T2 - 273.15
smooth_T2_C = smooth2d(T2_C, 3, cenweight=4)
lats, lons = latlon_coords(T2)
cart_proj = get_cartopy(T2)

fig = plt.figure(figsize=(14, 8))
ax = plt.axes(projection=cart_proj)
gl = ax.gridlines(draw_labels=True,linewidth=0, color='gray', alpha=0.5, linestyle='--', x_inline=False)
gl.left_labels = True
gl.rotate_labels = -0.1



states = NaturalEarthFeature(category="cultural", scale="50m",
                             facecolor="none",
                             name="admin_0_countries", edgecolor='black')
ax.add_feature(states, linewidth=1, edgecolor="black")

#contour = ax.contour(to_np(lons), to_np(lats), to_np(smooth_T2_C), 10, colors="black",
#                     transform=ccrs.PlateCarree())
levels = np.arange(np.floor(smooth_T2_C.min()), np.ceil(smooth_T2_C.max()) + 0.5, 0.5)
contourf = ax.contourf(to_np(lons), to_np(lats), to_np(smooth_T2_C), 10, levels = levels,
                       transform=ccrs.PlateCarree(),
                       cmap=matplotlib.colormaps.get_cmap("jet"))
cbar = plt.colorbar(contourf, ax=ax, shrink=.98, cmap=matplotlib.colormaps.get_cmap("jet"))
cbar.ax.text(0.5, -0.1, "Temperature at 2m(°C)", ha='center', va='center', transform=cbar.ax.transAxes)

ax.set_xlabel('X Coordinate (m)')
ax.set_ylabel('Y Coordinate (m)')

plt.show()
0

There are 0 best solutions below