proplot-dev / proplot

🎨 A succinct matplotlib wrapper for making beautiful, publication-quality graphics
https://proplot.readthedocs.io
MIT License
1.07k stars 96 forks source link

Plotting WRF output file example gives "AttributeError" #361

Closed donglx2018 closed 2 years ago

donglx2018 commented 2 years ago

Description

I tested the example of generating a surface plot from WRF output file on the web page (https://pratiman-91.github.io/2020/07/29/WRF-Surface-plot-using-Python.html).

Steps to reproduce

A "Minimal, Complete and Verifiable Example" will make it much easier for maintainers to help you.

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

Expected behavior: [What you expected to happen] https://pratiman-91.github.io/uploads/2020/07/29/Fig1.png

Actual behavior: When the script is executed, the following error occurs. β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€” Traceback (most recent call last): File "test.py", line 33, in m = axs.contourf(wrf.to_np(lons), wrf.to_np(lats), wrf.to_np(slp), File "/opt/anaconda3/lib/python3.8/site-packages/proplot/axes/plot.py", line 1889, in _redirect_or_standardize return func(self, args, kwargs) # call unbound method File "/opt/anaconda3/lib/python3.8/site-packages/proplot/axes/plot.py", line 4320, in contourf kw = self._parse_cmap(x, y, z, contour_plot=True, kw) File "/opt/anaconda3/lib/python3.8/site-packages/proplot/internals/warnings.py", line 96, in _deprecate_kwargs return func_orig(args, kwargs) File "/opt/anaconda3/lib/python3.8/site-packages/proplot/axes/plot.py", line 2924, in _parse_cmap norm, cmap, kwargs = self._parse_discrete(levels, norm, cmap, kwargs) File "/opt/anaconda3/lib/python3.8/site-packages/proplot/axes/plot.py", line 2777, in _parse_discrete norm = pcolors.DiscreteNorm( File "/opt/anaconda3/lib/python3.8/site-packages/proplot/internals/warnings.py", line 96, in _deprecate_kwargs return func_orig(*args, **kwargs) File "/opt/anaconda3/lib/python3.8/site-packages/proplot/colors.py", line 2417, in init self.vmin = vmin File "/opt/anaconda3/lib/python3.8/site-packages/matplotlib/colors.py", line 1148, in vmin if value != self._vmin: AttributeError: 'DiscreteNorm' object has no attribute '_vmin'

Proplot version

matplotlib version is 3.5.1 proplot version is 0.9.5

zxdawn commented 2 years ago

This is duplicated with #302. Please run your example with the newest version (not released yet): pip install git+https://github.com/lukelbd/proplot.git

donglx2018 commented 2 years ago

This is duplicated with #302. Please run your example with the newest version (not released yet): pip install git+https://github.com/lukelbd/proplot.git

Thanks, it works.

lukelbd commented 1 year ago

Note the newest proplot release 0.9.7 enforces a compatible matplotlib version when you install, and fixes some numpy dependency issues (#309). Sorry for not addressing this sooner.