You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
import wrf
from netCDF4 import Dataset
import proplot as plot
import cartopy.crs as crs
# Download the dataset from https://www.unidata.ucar.edu/software/netcdf/examples/wrfout_v2_Lambert.nc
# Load the dataset
ncfile = Dataset('wrfout_v2_Lambert.nc')
# Get the variable
slp = wrf.getvar(ncfile, "slp")
# Get the latitude and longitude points
lats, lons = wrf.latlon_coords(slp)
# Get the cartopy mapping object
cart_proj = wrf.get_cartopy(slp)
#Plotting
fig, axs = plot.subplots(proj=cart_proj)
# Define extents
lat = [lats.min(), lats.max()]
lon = [lons.min(), lons.max()]
#format the plot
axs.format(
lonlim=lon, latlim=lat,
labels=True, innerborders=True
)
#Plot using contourf
m = axs.contourf(wrf.to_np(lons), wrf.to_np(lats), wrf.to_np(slp),
transform=crs.PlateCarree(), cmap='roma_r')
#Adding colorbar with label
cbar = fig.colorbar(m, loc='b', label='Sea Level Pressure (hPa)')
#Saving the figure
fig.savefig('slp.png')
As you can see, the data is really that rectangle, and there's a lot of empty space created. The best I can do is by referencing the XLONG and XLAT from the corners of the slp data, by using lonlim=[slp[0,-1].XLONG,slp[-1,0].XLONG],latlim=[slp[-1,0].XLAT,slp[0,-1].XLAT].
fig, axs = plot.subplots(proj=cart_proj)
# Define extents
lat = [lats.min(), lats.max()]
lon = [lons.min(), lons.max()]
#format the plot
axs.format(
#lonlim=lon, latlim=lat,
lonlim=[slp[0,-1].XLONG,slp[-1,0].XLONG],latlim=[slp[-1,0].XLAT,slp[0,-1].XLAT],
labels=True, innerborders=True
)
#Plot using contourf
m = axs.contourf(wrf.to_np(lons), wrf.to_np(lats), wrf.to_np(slp),
transform=crs.PlateCarree(), cmap='roma_r')
#Adding colorbar with label
cbar = fig.colorbar(m, loc='b', label='Sea Level Pressure (hPa)')
#Saving the figure
fig.savefig('slp.png')
This leaves no empty space on the sides, but there's still empty spaces on top and bottom. I have tried other combination, but the others simply cutoff the data area.
I would like help with this. The wrf-python recommends cartopy, but the plots simply don't have any tick marks for latlon.
Edit 1:
This refers to the above code. How do I tell the codes above to use basemap instead of cartopy? I'm looking into plotting over the South Pole. And I do not have any success using Cartopy with the base matplotlib. I would like to try using proplot with basemap as the backend. I could not figure out where to insert backend = 'basemap'.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Hello. I'm following the guide in this page. https://pratiman-91.github.io/2020/07/29/WRF-Surface-plot-using-Python.html. The code given is as below. The image output is as below.
As you can see, the data is really that rectangle, and there's a lot of empty space created. The best I can do is by referencing the XLONG and XLAT from the corners of the slp data, by using
lonlim=[slp[0,-1].XLONG,slp[-1,0].XLONG],latlim=[slp[-1,0].XLAT,slp[0,-1].XLAT]
.This leaves no empty space on the sides, but there's still empty spaces on top and bottom. I have tried other combination, but the others simply cutoff the data area.
I would like help with this. The wrf-python recommends cartopy, but the plots simply don't have any tick marks for latlon.
Edit 1:
This refers to the above code. How do I tell the codes above to use basemap instead of cartopy? I'm looking into plotting over the South Pole. And I do not have any success using Cartopy with the base matplotlib. I would like to try using proplot with basemap as the backend. I could not figure out where to insert
backend = 'basemap'
.Beta Was this translation helpful? Give feedback.
All reactions