Comments (5)
hm this smells like something between matplotlib and cartopy, that's not a function seaborn is calling directly. can you share the full traceback?
from seaborn.
Here is the full traceback:
File ~\Miniconda3\envs\figs\Lib\site-packages\spyder_kernels\py3compat.py:356 in compat_exec
exec(code, globals, locals)
File c:\users\bschweigert2\desktop\lm clim\error_ex.py:28
kde = sns.kdeplot(x = lons, y = lats, fill = True, transform = ccrs.PlateCarree(), zorder = 1)
File ~\Miniconda3\envs\figs\Lib\site-packages\seaborn\distributions.py:1682 in kdeplot
color = _default_color(method, hue, color, kwargs)
File ~\Miniconda3\envs\figs\Lib\site-packages\seaborn\utils.py:136 in _default_color
scout = method([], [], **kws)
File ~\Miniconda3\envs\figs\Lib\site-packages\matplotlib_init_.py:1478 in inner
return func(ax, *map(sanitize_sequence, args), **kwargs)
File ~\Miniconda3\envs\figs\Lib\site-packages\matplotlib\axes_axes.py:5509 in fill_between
return self._fill_between_x_or_y(
File ~\Miniconda3\envs\figs\Lib\site-packages\matplotlib\axes_axes.py:5500 in _fill_between_x_or_y
up_x, up_y = kwargs["transform"].contains_branch_seperately(self.transData)
AttributeError: 'PlateCarree' object has no attribute 'contains_branch_seperately'
That would be intriguing, because I have done plenty of plotting recently with matplotlib and cartopy with no issues thus far. Thanks for the help!
from seaborn.
Based on that it seems like you could reproduce this with something like
f, ax = plt.subplots()
ax.fill_between([], [], transform=ccrs.PlateCarree())
(untested as I don't have the relevant geographic dependencies)
from seaborn.
You may need to set up the subplot with the same projection too, I am not sure.
from seaborn.
@bschweigert , I've been looking into this one too.
I compared to code from 0.9 branch (I saw it was working from someone on stack exchange in 2020 so picked the branch of that year).
Back then the kwargs
being fed into seaborn.distributions.kdeplot
went straight to _bivariate_kdeplot_
or _univariate_kdeplot
, which later feeds the kwargs into ax.contourf
or ax.contour
which I believe is managed by matplotlib.
However, somewhere along the way (about 3 years ago), this was added before the kwargs can get to plot_univariate_density
or plot_bivariate_density
color = _default_color(method, hue, color, kwargs)
It consequently tries to pass in the transform
kwarg into the fill_between
method in matplotlib - the tricky bit is that fill_between
does accept the transform kwarg, except it must be a matplotlib.transform type!
I am not sure if you might still encounter the error with a univariate density plot with fill=True
because it does look like it can calll fill_between
. I haven't tested/looked further into this.
But it seems to work fine on a bivariate density maybe because contourf
supports the cartopy projection? transform
is an argument for matplotlib.contour.ContourSet
and seems to accept a wide range of transformation types based on the get_transform
function. This function converts the transform variable to a matplotlib.Transform
type.
A workaround for you to continue forward is to do this:
kde = sns.kdeplot(x = lons, y = lats, fill = True, transform = ccrs.PlateCarree()._as_mpl_transform(ax), zorder = 1)
as cartopy projections have a (private) method to convert to matplotlib transform types.
Whether this is a bug by seaborn, or by matplotlib - I don't know. Maybe matplotlib should convert all transforms to a matplotlib type first in fill_between
, or maybe seaborn should be doing the conversion - or maybe transform
type should be first checked to prevent passing into _default_color()
as I don't think it's doing much with that information anyway.
@mwaskom , let me know if you would like to me to raise a PR to address this if one of the suggestions is something you would want to implement in seaborn.
from seaborn.
Related Issues (20)
- Incorrect plotting of exactly overlapping scatter with `hue` and `hue_order` HOT 3
- Adding plot type metadata to support textual figure descriptions HOT 2
- TypeError: Cannot interpret 'Float64Dtype()' as a data type with pandas extension types HOT 2
- Consider adding mpl.Figure as an optional argument to subplot functions / classes. HOT 1
- AttributeError: module 'numpy' has no attribute 'typeDict'
- categorical plots - unused categories mess up element spacing and width HOT 4
- Customizing context or style as in seaborn as in matplotlib? HOT 1
- Introducing `seaborn_objects_recipes` Library HOT 2
- secondary y axis is messing up the y-axis labels HOT 1
- Adding precomputed errorbars to pointplot HOT 1
- Seaborn with scanpy and statannotations HOT 1
- Linear regression constrained to pass through origin HOT 2
- Dual axis plot broken in 0.13.2 (vs. 0.12.2) HOT 2
- Controlling color of both line and bar at same time using object interface HOT 4
- How to hide legend while using seaborn.objects? HOT 1
- Cannot plot certain data with kdeplot, warning that dataset has 0 variance which is not. HOT 1
- Older Versions of Seaborn Incompatible with Matplotlib 3.9.x HOT 3
- TypeError with seaborn.kdeplot when using fill=True and categorical hue HOT 3
- ModuleNotFoundError: No module named 'seaborn' HOT 1
- `so.Range()` cannot be "overplotted" by an additional mark added with so.Plot.add() HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from seaborn.