has2k1 / plotnine

A Grammar of Graphics for Python
https://plotnine.org
MIT License
4.02k stars 217 forks source link

geom_density_2d weird render using levels for filling #174

Closed raphaelcampos closed 6 years ago

raphaelcampos commented 6 years ago

When I run the script bellow:

(
    ggplot(df_merged, aes(x='x', y='y')) +
    stat_density_2d(aes(fill='..level..'), color=None, geom = "polygon", alpha = 1.0, levels = 15) +
    facet_grid('churn~.') 
)

I get the following result.

image

It seems that is being caused by the fact that the contour lines are being cut. Once, I change the script to increase the limits of x I can get a good plot.

(
    ggplot(df_merged, aes(x='x', y='y')) +
    stat_density_2d(aes(fill='..level..'), color=None, geom = "polygon", alpha = 1.0, levels = 15) +
    facet_grid('churn~.') +
    xlim(-0.2, 1.2)
)

image

I am not sure whether or not this is an anomalous behavior;

has2k1 commented 6 years ago

This is a known issue that has no resolution. The "weirdness" shows up when the data limits are not sufficient to contain most of at least one single level. The solution is to have the levels computed over a larger space, i.e. extend the limits.

has2k1 commented 6 years ago

Closed as wontfix because I do not envision a solution.