I keep getting this error whenever I try to plot a choropleth:
AttributeError Traceback (most recent call last)
Input In [337], in <cell line: 15>()
13 scheme =mc.EqualInterval(pro['total'], k=10)# mc.UserDefined(reach_map['reach_equivalent'], bins=[0,10,20,30,40,50,60])
14 #Map
---> 15 gplt.choropleth(pro,
16 hue="total",
17 linewidth=.2,
18 cmap='inferno_r',
19 scheme=scheme,
20 legend=True,
21 edgecolor='black',
22 ax=ax
23 );
24 ax.set_title('CAD CDC hospitalization', fontsize=13)
File ~\anaconda3\envs\geo_env\lib\site-packages\geoplot\geoplot.py:995, in choropleth(df, projection, hue, cmap, norm, scheme, legend, legend_kwargs, legend_labels, legend_values, extent, figsize, ax, **kwargs)
991 ax.add_patch(feature)
993 return ax
--> 995 plot = ChoroplethPlot(
996 df, figsize=figsize, ax=ax, extent=extent, projection=projection,
997 hue=hue, scheme=scheme, cmap=cmap, norm=norm,
998 legend=legend, legend_values=legend_values, legend_labels=legend_labels,
999 legend_kwargs=legend_kwargs, **kwargs
1000 )
1001 return plot.draw()
File ~\anaconda3\envs\geo_env\lib\site-packages\geoplot\geoplot.py:965, in choropleth.<locals>.ChoroplethPlot.__init__(self, df, **kwargs)
964 def __init__(self, df, **kwargs):
--> 965 super().__init__(df, **kwargs)
966 self.set_hue_values(color_kwarg=None, default_color=None)
967 self.paint_legend(supports_hue=True, supports_scale=False)
File ~\anaconda3\envs\geo_env\lib\site-packages\geoplot\geoplot.py:628, in Plot.__init__(self, df, **kwargs)
626 self.projection = kwargs.pop('projection')
627 # TODO: init_axes() -> init_axes(ax)
--> 628 self.init_axes()
629 self.kwargs = kwargs
File ~\anaconda3\envs\geo_env\lib\site-packages\geoplot\geoplot.py:639, in Plot.init_axes(self)
637 extrema = np.array([0, 0, 1, 1]) # default Matplotlib plot extent
638 else:
--> 639 xmin, ymin, xmax, ymax = self.df.total_bounds
640 # Plots suffer clipping issues if we use just the geometry extrema due to plot features
641 # that fall outside of the viewport. The most common case is the edges of polygon
642 # patches with non-zero linewidth. We partially ameliorate the problem by increasing
(...)
645 # degrees varies depending on where you are on the globe. Since the effect is small we
646 # ignore this problem here, for simplicity's sake.
647 extrema = relax_bounds(xmin, ymin, xmax, ymax)
File ~\anaconda3\envs\geo_env\lib\site-packages\pandas\core\generic.py:5575, in NDFrame.__getattr__(self, name)
5568 if (
5569 name not in self._internal_names_set
5570 and name not in self._metadata
5571 and name not in self._accessors
5572 and self._info_axis._can_hold_identifiers_and_holds_name(name)
5573 ):
5574 return self[name]
-> 5575 return object.__getattribute__(self, name)
AttributeError: 'DataFrame' object has no attribute 'total_bounds'
This is my code
import mapclassify as mc
import matplotlib.pyplot as plt
import geopandas as gpd
import geoplot as gplt
import cartopy.crs as ccrs
import pandas as pd
import pprint as pp
import seaborn as sns
import cartopy.crs as ccrs
from mpl_toolkits.axes_grid1 import make_axes_locatable
fig, ax = plt.subplots(1, 1, figsize=(12, 10))
scheme =mc.EqualInterval(pro['total'], k=10)
#Map
gplt.choropleth(pro,
hue="total",
linewidth=.2,
cmap='inferno_r',
scheme=scheme,
legend=True,
edgecolor='black',
ax=ax
);
ax.set_title('CAD CDC hospitalization', fontsize=13)
Can anyone help me out with this? I'm not entirely sure where the error is coming from or what is causing it,I've tried manipulating each of the types of the data that I want to plot but it doesn't help much. I tried checking if there is an issue with the type of the geometry used to plot but thats not helping either.