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

The KDE plot is strange when extent is not specified in transform_density #3203

Closed
j4ggr opened this issue Sep 28, 2023 · 5 comments
Closed
Labels

Comments

@j4ggr
Copy link

j4ggr commented Sep 28, 2023

When I use the given example for a KDE plot, I also get the expected result:

import altair as alt
from vega_datasets import data

source = data.iris()

alt.Chart(source).transform_fold(
    ['petalWidth',
     'petalLength',
     'sepalWidth',
     'sepalLength'],
    as_ = ['Measurement_type', 'value']
).transform_density(
    density='value',
    bandwidth=0.3,
    groupby=['Measurement_type'],
    extent=[0, 8]
).mark_area().encode(
    alt.X('value:Q'),
    alt.Y('density:Q'),
    alt.Color('Measurement_type:N')
)

image

But as soon as I remove the optional extent specification, the chart looks pretty bad:

import altair as alt
from vega_datasets import data

source = data.iris()

alt.Chart(source).transform_fold(
    ['petalWidth',
     'petalLength',
     'sepalWidth',
     'sepalLength'],
    as_ = ['Measurement_type', 'value']
).transform_density(
    density='value',
    bandwidth=0.3,
    groupby=['Measurement_type']
).mark_area().encode(
    alt.X('value:Q'),
    alt.Y('density:Q'),
    alt.Color('Measurement_type:N')
)

image

Versions

Python: 3.11.1
Altair: 5.1.1

@j4ggr j4ggr added the bug label Sep 28, 2023
@jonmmease
Copy link
Contributor

Thanks for the report @j4ggr, I think this likely has the same root cause as vega/vega-lite#9078. The fix for this has been merged into Vega-Lite in vega/vega-lite#9106, but we need to wait for a Vega-Lite release in order to update Altair with the fix.

@joelostblom
Copy link
Contributor

This is working as expected in altair 5.1.2 so closing this issue

@marianokamp
Copy link

marianokamp commented May 30, 2024

image
Still broken for me @joelostblom. How did you verify that it does not break anymore? My steps to reproduce:

  • Install 5.1.2 (or 5.2.0 or 5.3.0)
  • Restart Jupyter Kernel
  • Execute 2nd code snippet.

marianokamp added a commit to aws-samples/amazon-sagemaker-amt-visualize that referenced this issue May 30, 2024
@joelostblom
Copy link
Contributor

@marianokamp If you recently installed the new version of ALtair, make sure you clear all outputs in the notebook and then restart jupyterlab (not just the kernel). Otherwise an old version of VegaLite might still be used in the background.

@marianokamp
Copy link

@joelostblom Re-installed 5.3, then restarted jupyterlab (not just the kernel): Now the 2nd code example, without extent, works. Thank you.

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

No branches or pull requests

4 participants