Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

kdeplot not working when fill=True #289

Open
jose-vines-toteat opened this issue Jan 2, 2024 · 3 comments · May be fixed by #296
Open

kdeplot not working when fill=True #289

jose-vines-toteat opened this issue Jan 2, 2024 · 3 comments · May be fixed by #296

Comments

@jose-vines-toteat
Copy link

Hi, I tried reproducing your example in the documentation, and I get this error when using kdeplot with fill=True

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
Cell In[104], line 3
      1 # ax = gplt.polyplot(gdf_cl[gdf_cl.Region == 'Región Metropolitana de Santiago'], projection=gcrs.WebMercator(), zorder=1)
      2 ax = gplt.webmap(gdf_cl[gdf_cl.Region == 'Región Metropolitana de Santiago'], projection=gcrs.WebMercator(), zorder=1)
----> 3 gplt.kdeplot(view[['geometry', 'sale']], cmap='viridis', ax=ax, thresh=.05, legend=True, fill=True)

File ~/mambaforge/envs/ds/lib/python3.9/site-packages/geoplot/geoplot.py:1320, in kdeplot(df, projection, extent, figsize, ax, clip, **kwargs)
   1315         return ax
   1317 plot = KDEPlot(
   1318     df, projection=projection, extent=extent, figsize=figsize, ax=ax, clip=clip, **kwargs
   1319 )
-> 1320 return plot.draw()

File ~/mambaforge/envs/ds/lib/python3.9/site-packages/geoplot/geoplot.py:1304, in kdeplot.<locals>.KDEPlot.draw(self)
   1301     return ax
   1303 if self.projection:
-> 1304     sns.kdeplot(
   1305         x=pd.Series([p.x for p in self.df.geometry]),
   1306         y=pd.Series([p.y for p in self.df.geometry]),
   1307         transform=ccrs.PlateCarree(), ax=ax, **self.kwargs
   1308     )
   1309 else:
   1310     sns.kdeplot(
   1311         x=pd.Series([p.x for p in self.df.geometry]),
   1312         y=pd.Series([p.y for p in self.df.geometry]),
   1313         ax=ax, **self.kwargs
   1314     )

File ~/mambaforge/envs/ds/lib/python3.9/site-packages/seaborn/distributions.py:1682, in kdeplot(data, x, y, hue, weights, palette, hue_order, hue_norm, color, fill, multiple, common_norm, common_grid, cumulative, bw_method, bw_adjust, warn_singular, log_scale, levels, thresh, gridsize, cut, clip, legend, cbar, cbar_ax, cbar_kws, ax, **kwargs)
   1679 p._attach(ax, allowed_types=["numeric", "datetime"], log_scale=log_scale)
   1681 method = ax.fill_between if fill else ax.plot
-> 1682 color = _default_color(method, hue, color, kwargs)
   1684 if not p.has_xy_data:
   1685     return ax

File ~/mambaforge/envs/ds/lib/python3.9/site-packages/seaborn/utils.py:159, in _default_color(method, hue, color, kws, saturation)
    156 elif method.__name__ == "fill_between":
    158     kws = _normalize_kwargs(kws, mpl.collections.PolyCollection)
--> 159     scout = method([], [], **kws)
    160     facecolor = scout.get_facecolor()
    161     color = to_rgb(facecolor[0])

File ~/mambaforge/envs/ds/lib/python3.9/site-packages/matplotlib/__init__.py:1465, in _preprocess_data.<locals>.inner(ax, data, *args, **kwargs)
   1462 @functools.wraps(func)
   1463 def inner(ax, *args, data=None, **kwargs):
   1464     if data is None:
-> 1465         return func(ax, *map(sanitize_sequence, args), **kwargs)
   1467     bound = new_sig.bind(ax, *args, **kwargs)
   1468     auto_label = (bound.arguments.get(label_namer)
   1469                   or bound.kwargs.get(label_namer))

File ~/mambaforge/envs/ds/lib/python3.9/site-packages/matplotlib/axes/_axes.py:5509, in Axes.fill_between(self, x, y1, y2, where, interpolate, step, **kwargs)
   5507 def fill_between(self, x, y1, y2=0, where=None, interpolate=False,
   5508                  step=None, **kwargs):
-> 5509     return self._fill_between_x_or_y(
   5510         "x", x, y1, y2,
   5511         where=where, interpolate=interpolate, step=step, **kwargs)

File ~/mambaforge/envs/ds/lib/python3.9/site-packages/matplotlib/axes/_axes.py:5500, in Axes._fill_between_x_or_y(self, ind_dir, ind, dep1, dep2, where, interpolate, step, **kwargs)
   5498 up_x = up_y = True
   5499 if "transform" in kwargs:
-> 5500     up_x, up_y = kwargs["transform"].contains_branch_seperately(self.transData)
   5501 self.update_datalim(pts, updatex=up_x, updatey=up_y)
   5503 self.add_collection(collection, autolim=False)

AttributeError: 'PlateCarree' object has no attribute 'contains_branch_seperately'
@tfardet
Copy link

tfardet commented Jan 22, 2024

I can confirm this issue, it is an incompatibility with matplotlib 3.8.
Until it is fixed, you can install matplotlib 3.7 (pip install "matplotlib<3.8") to be able to plot with fill=True

@LFK01
Copy link

LFK01 commented May 28, 2024

I too confirm this issue but could not resolve it by installing matplotlib<3.8 neither by installing matplotlib==3.7

@nicholas-ys-tan
Copy link

@ResidentMario , are you still accepting PRs for this repository?

I've investigated this issue and have a fix that can work. It is due to updates in seaborn as they pass in the kwargs through another function first which can't process a cartopy transform, and only accepts matplotlib.transform.

I've detailed my findings here: mwaskom/seaborn#3694 (comment)

The work around I proposed to OP in that issue would also work here.

I noted this repository hasn't had any commits in a long time, may I be able to assist?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants