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

seaborn.kdeplot is not suitable for point patterns #305

Open
martinfleis opened this issue Sep 16, 2023 · 1 comment · Fixed by pysal/pointpats#118
Open

seaborn.kdeplot is not suitable for point patterns #305

martinfleis opened this issue Sep 16, 2023 · 1 comment · Fixed by pysal/pointpats#118

Comments

@martinfleis
Copy link

In the chapter Point Pattern Analysis, you suggest using seaborn.kdeplot to do KDE over a point pattern based on coordinates. However, the result is wrong. Only because the bounding box of the dataframe is roughly square, the issue is not noticeable, but as soon as the dataframe becomes more elongated, the KDE gets stretched along the longer dimension.

The alternative is to use sklearn's implementation of KernelDensity instead, but that means building the whole thing yourself, instead of a single call to seaborn.

I have noticed this reported on mastodon and figured out what is happening in the following thread. The issue has been reported to seaborn (mwaskom/seaborn#3472), but it boils down to the behavior of scipy's gaussian_kde, which estimates the bandwidth independently for each variable, which is wrong in our case where the bandwidth linked to a euclidean distance between the points.

I think that until there is a change in scipy that is exposed in seaborn, we should not use or suggest using seaborn.kdeplot on point patterns.

@ljwolf
Copy link
Member

ljwolf commented Sep 16, 2023

Makes a lot of sense. We should probably write a plot_density() function of our own for pointpats in light of this

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.

2 participants