I am trying to plot a geodataframe with geoplot, and cannot work out the solution to ValueError: Axis limits cannot be NAN or Inf


Linux (Ubuntu 19.10, x86_64)


    Cu_ppm  geometry
0   26.1    POINT (410897.000 7089554.000)
1   31.5    POINT (410896.000 7089604.000)
2   31.3    POINT (410896.000 7089654.000)
3   48.6    POINT (410897.000 7089704.000)
4   32.3    POINT (410896.000 7089754.000)

<class 'geopandas.geodataframe.GeoDataFrame'>
Int64Index: 16904 entries, 0 to 17160
Data columns (total 2 columns):
 #   Column    Non-Null Count  Dtype   
---  ------    --------------  -----   
 0   Cu_ppm    16904 non-null  float64 
 1   geometry  16904 non-null  geometry
dtypes: float64(1), geometry(1)
memory usage: 396.2 KB

<Projected CRS: EPSG:2955>
Name: NAD83(CSRS) / UTM zone 11N
Axis Info [cartesian]:
- E[east]: Easting (metre)
- N[north]: Northing (metre)
Area of Use:
- name: Canada - 120°W to 114°W
- bounds: (-120.0, 48.99, -114.0, 83.5)
Coordinate Operation:
- name: UTM zone 11N
- method: Transverse Mercator
Datum: NAD83 Canadian Spatial Reference System
- Ellipsoid: GRS 1980
- Prime Meridian: Greenwich
# getting rid of nan and inf values in pandas dataframe
cudb.replace([np.inf, -np.inf], np.nan)
# capturing null values in converted geodataframe


The geodataframe plots quite nicely through geopandas, using


I cannot, however, figure out how to plot the same geodataframe through geoplot. Here is the stack trace to the error:


ValueError                             Traceback (most recent call last)
<ipython-input-41-e41db0633766> in <module>
----> 1 gplt.pointplot(cugdf)

~/.miniconda3/envs/geostat/lib/python3.8/site-packages/geoplot/geoplot.py in pointplot(df, projection, hue, cmap, norm, scheme, scale, limits, scale_func, legend, legend_var, legend_values, legend_labels, legend_kwargs, figsize, extent, ax, **kwargs)
    798             return ax
--> 800     plot = PointPlot(
    801         df, figsize=figsize, ax=ax, extent=extent, projection=projection,
    802         hue=hue, scheme=scheme, cmap=cmap, norm=norm,

~/.miniconda3/envs/geostat/lib/python3.8/site-packages/geoplot/geoplot.py in __init__(self, df, **kwargs)
    773     class PointPlot(Plot, HueMixin, ScaleMixin, LegendMixin):
    774         def __init__(self, df, **kwargs):
--> 775             super().__init__(df, **kwargs)
    776             self.set_hue_values(color_kwarg='color', default_color='steelblue')
    777             self.set_scale_values(size_kwarg='s', default_size=5)

~/.miniconda3/envs/geostat/lib/python3.8/site-packages/geoplot/geoplot.py in __init__(self, df, **kwargs)
    602         self.projection = kwargs.pop('projection')
    603         # TODO: init_axis() -> init_axis(ax)
--> 604         self.init_axis()
    605         self.kwargs = kwargs

~/.miniconda3/envs/geostat/lib/python3.8/site-packages/geoplot/geoplot.py in init_axis(self)
    690             else:
    691                 ax.axison = False
--> 692                 ax.set_xlim((xmin, xmax))
    693                 ax.set_ylim((ymin, ymax))

~/.miniconda3/envs/geostat/lib/python3.8/site-packages/matplotlib/axes/_base.py in set_xlim(self, left, right, emit, auto, xmin, xmax)
   3183         self._process_unit_info(xdata=(left, right))
-> 3184         left = self._validate_converted_limits(left, self.convert_xunits)
   3185         right = self._validate_converted_limits(right, self.convert_xunits)

~/.miniconda3/envs/geostat/lib/python3.8/site-packages/matplotlib/axes/_base.py in _validate_converted_limits(self, limit, convert)
   3099             if (isinstance(converted_limit, Real)
   3100                     and not np.isfinite(converted_limit)):
-> 3101                 raise ValueError("Axis limits cannot be NaN or Inf")
   3102             return converted_limit

ValueError: Axis limits cannot be NaN or Inf

I'm clearly missing something but I can't figure it out...

1 Answer 1


So far I have failed to use geopy to plot geodataframes whose coordinates are carthesian (i.e. in [m], rather than lat, lon [degrees]). I mostly use data with epsg=3006, and geoplot then just draws a blank canvas. As a test you could try reprojecting to e.g. WGS 84, which gives lat, lon coordinates, and see if geoplot works then.

cugdf = cugdf.to_crs(epsg=4326)

  • Interesting. I'll be happy if this works and disappointed if utm is the problem... it's an easy conversion but my industry relies on utm almost exclusively!! Will post again when I get back to my computer. Thanks
    – skytwosea
    May 16, 2020 at 18:30
  • Your suggestion got me part of the way there, thank you! I converted to wgs84, and now it plots, but only a single point is visible in the map field because the bounds of the plot are global: cugdf.crs -> bounds: (-180.0, -90.0, 180.0, 90.0) Do you know how to change the bounds? I also think this might help with plotting the native UTM crs: the bounds on the original dataframe were bounds: (-120.0, 48.99, -114.0, 83.5) but the geometry points were six and seven digit floating point falues, which numerically fall outside of the crs bounds...
    – skytwosea
    May 17, 2020 at 19:48
  • same thing converting to more general UTM zone (north): epsg 32633. Datapoints are 7 digit floating points, eg. POINT (-1600223.122 12086492.764) but bounds of the crs are much smaller, eg. bounds: (12.0, 0.0, 18.0, 84.0). The map is plotting without error but the map field is blank, as the points are outside of the bounds
    – skytwosea
    May 17, 2020 at 19:59
  • Try setting the projection as well, e.g.: cugdf.plot(projection=gplt.crs.TransverseMercator(your_params)) , and if you're also defining a separate figure window: plt.subplot(111, projection=gplt.crs.TransverseMercator(your_params)) May 17, 2020 at 20:16
  • So, turns out if the stack trace says there's a duck, then there's a duck. A friend pointed me back to the original dataframe, and there were NANs in my original easting & northing columns. So that problem is solved.
    – skytwosea
    May 18, 2020 at 21:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.