Geographic Information Systems Asked by skytwosea on April 14, 2021
I am trying to plot a geodataframe with geoplot, and cannot work out the solution to ValueError: Axis limits cannot be NAN or Inf
Context:
Linux (Ubuntu 19.10, x86_64)
cugdf.head():
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)
cugdf.info():
<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
cugdf.crs:
<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)
cudb.dropna(inplace=True)
# capturing null values in converted geodataframe
cugdf.isnull().values.sum():
0
The geodataframe plots quite nicely through geopandas, using
cugdf.plot()
I cannot, however, figure out how to plot the same geodataframe through geoplot. Here is the stack trace to the error:
gplt.pointplot(cugdf):
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
799
--> 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
606
~/.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))
694
~/.miniconda3/envs/geostat/lib/python3.8/site-packages/matplotlib/axes/_base.py in set_xlim(self, left, right, emit, auto, xmin, xmax)
3182
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)
3186
~/.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
3103
ValueError: Axis limits cannot be NaN or Inf
I’m clearly missing something but I can’t figure it out…
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)
Answered by user8188435 on April 14, 2021
Get help from others!
Recent Questions
Recent Answers
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP