vega / altair

Declarative statistical visualization library for Python
https://altair-viz.github.io/
BSD 3-Clause "New" or "Revised" License
9.32k stars 794 forks source link

Add an example that showcases the different interpolation methods #3322

Closed thomascamminady closed 9 months ago

thomascamminady commented 9 months ago

I frequently find myself not fully knowing which interpolation method (as a parameter for mark_line(interpolate=...)) yields which result.

I created the below chart that I rely on. I wonder whether something like this could be added as an example.

import altair as alt 
import pandas as pd
df = pd.DataFrame(
    {
        "x": [0, 1, 2, 3, 4, 5, 6, 7, 8, 9],
        "y": [1, 2, 3, 3, 4, 0, 0, 9, 6, 9], # random data
    }
)
base = alt.Chart(df).encode(x="x:Q", y="y:Q").properties(width=1200, height=120)

alt.vconcat(
    *[
        alt.layer(
            base.mark_point(),
            base.mark_line(interpolate=method),
        ).properties(title=f"Interpolation method: {method}")
        for method in [
            "basis",
            "basis-open",
            "basis-closed",
            "bundle",
            "cardinal",
            "cardinal-open",
            "cardinal-closed",
            "catmull-rom",
            "linear",
            "linear-closed",
            "monotone",
            "natural",
            "step",
            "step-before",
            "step-after",
        ]
    ]
)

visualization

joelostblom commented 9 months ago

I agree that it is hard to remember these and convenient to have them all in one place. I think we already have that in the documentation since we added the detailed parameter info for each mark. For example, for the line interpolation, one can try them all out via the dropdown menu here https://altair-viz.github.io/user_guide/marks/line.html (to go through them faster you can use the up/down arrow keys once the dropdown is activated).

I can see that not all options that you have included here are in the dropdown menu. Would you want to create a PR adding in the missing ones? Or do you think there is some other advantage added by your solution that I'm missing?

thomascamminady commented 9 months ago

Thanks @joelostblom for the detailed answer. I did completely miss the example, sorry! I don't think there's any added value in my example then. I will create a PR, adding the missing methods.