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

NotImplementedError when using "globe = True" #378

Closed LirenW closed 1 year ago

LirenW commented 1 year ago

Description

I met an error "NotImplementedError: Must supply an integer axis value" when I was tring to plot some data with "npaeqd" projection.

The full output are as follows:

NotImplementedError                       Traceback (most recent call last)
/ddn_lustre/kernel_script/demo.ipynb Cell 5 in <cell line: 7>()
      [1](vscode-notebook-cell://ssh-remote%2B7b22686f73744e616d65223a22424e55227d/ddn_lustre/kernel_script/demo.ipynb#ch0000009vscode-remote?line=0) fig, axs = pplt.subplots(ncols=1,
      [2](vscode-notebook-cell://ssh-remote%2B7b22686f73744e616d65223a22424e55227d/ddn_lustre/kernel_script/demo.ipynb#ch0000009vscode-remote?line=1)                         proj="npaeqd",
      [3](vscode-notebook-cell://ssh-remote%2B7b22686f73744e616d65223a22424e55227d/ddn_lustre/kernel_script/demo.ipynb#ch0000009vscode-remote?line=2)                         refwidth=4, 
      [4](vscode-notebook-cell://ssh-remote%2B7b22686f73744e616d65223a22424e55227d/ddn_lustre/kernel_script/demo.ipynb#ch0000009vscode-remote?line=3)                         boundinglat=30)
      [5](vscode-notebook-cell://ssh-remote%2B7b22686f73744e616d65223a22424e55227d/ddn_lustre/kernel_script/demo.ipynb#ch0000009vscode-remote?line=4) axs.format(**set_pplt_axs_polar_figure())
----> [7](vscode-notebook-cell://ssh-remote%2B7b22686f73744e616d65223a22424e55227d/ddn_lustre/kernel_script/demo.ipynb#ch0000009vscode-remote?line=6) m = axs[0].contourf(FSNT_NH_yr_avg.sel(exp=EXP_NAME[0]), globe=True)

File ~/anaconda3/lib/python3.9/site-packages/proplot/internals/process.py:284, in _preprocess_args.<locals>.decorator.<locals>._redirect_or_standardize(self, *args, **kwargs)
    281             ureg.setup_matplotlib(True)
    283 # Call main function
--> 284 return func(self, *args, **kwargs)

File ~/anaconda3/lib/python3.9/site-packages/proplot/axes/plot.py:3859, in PlotAxes.contourf(self, x, y, z, **kwargs)
   3852 @process._preprocess_args('x', 'y', 'z')
   3853 @docstring._concatenate_inherited
   3854 @docstring._snippet_manager
   3855 def contourf(self, x, y, z, **kwargs):
   3856     """
   3857     %(plot.contourf)s
   3858     """
-> 3859     x, y, z, kw = self._parse_plot2d(x, y, z, **kwargs)
   3860     kw.update(_pop_props(kw, 'collection'))
...
--> 808         raise NotImplementedError("Must supply an integer axis value")
    810 if not isinstance(repeats, Integral):
    811     raise NotImplementedError("Only integer valued repeats supported")

NotImplementedError: Must supply an integer axis value

Steps to reproduce

Unfortunately, I cannot fully reproduce the error with demo data. The plot script I used like this:

import numpy as np
import xarray as xr
import proplot as pplt
import pandas as pd

ds = xr.tutorial.load_dataset("air_temperature")
air = ds.air.isel(time=[0, 724]) - 273.15

exp = ['ctl', 'exp']
air2 = xr.DataArray(air.values, coords=[exp, air.lat, air.lon], dims=['exp', 'lat', 'lon'])

fig, axs = pplt.subplots(ncols=1,
                        proj="npaeqd",
                        refwidth=4, 
                        boundinglat=30)

m = axs[0].contourf(air2.sel(exp='ctl'), globe=True)

This script runs normally but when I use my data and set the globe = True, an 'NotImplementedError' occured.

The data I used shape like this and it plots normally without setting the globe keywords:

'FSNT'  exp: 5 lat: 64 lon: 288
lat  (lat)  float64  30.63 31.57 32.51 ... 89.06 90.0
lon  (lon)  float64 0.0 1.25 2.5 ... 356.2 357.5 358.8
exp  (exp)  object  'CTL' 'N1' 'N2' 'P1' 'P2'

Equivalent steps in matplotlib

Please try to make sure this bug is related to a proplot-specific feature. If you're not sure, try to replicate it with the native matplotlib API. Matplotlib bugs belong on the matplotlib github page.

# your code here, if applicable
import matplotlib.pyplot as plt

Proplot version

Paste the results of import matplotlib; print(matplotlib.__version__); import proplot; print(proplot.version) here. 3.4.3 0.9.5

lukelbd commented 1 year ago

Sorry, not much I can do if we can't reproduce the error. Also not sure where the error triggers since that message is truncated, but I don't emit any NotImplementedErrors in proplot, so it must be external (numpy, matplotlib, or cartopy). Maybe in your code you somehow passed the wrong axis keyword, and you did that at the same time as passing globe=True? Anyway will close for now barring further updates.