James Chang
James Chang

Reputation: 630

In Altair, how to set the size of the connected points in a line chart?

I want to plot a line chart (with connected point markers) in Altair. I know how to change the linewidth (by setting the strokeWidth) but I don't know how I can change the size of these point markers. Below is my code:

altair.Chart(ys.reset_index()).mark_line(point=True, strokeWidth=5).encode(
        x="Time:T",
        y="HL:Q",
        color=altair.Color(
            "Time Series Component",
            scale=altair.Scale(scheme="dark2")
        ),
        tooltip=["Time Series Component", "Time", "HL"]
    ).interactive().properties(
        width=1000,
        height=500
    ).configure_axis(
        labelFontSize=20,
        titleFontSize=20
    ).configure_legend(
        orient="right"
    )

Upvotes: 9

Views: 6780

Answers (1)

jakevdp
jakevdp

Reputation: 86463

One way to do it is to use configure_point(size=SIZE). For example:

import altair as alt
import pandas as pd
import numpy as np

np.random.seed(0)

ys = pd.DataFrame({
    'Time': pd.date_range('2019-01-01', freq='D', periods=30),
    'HL': np.random.randn(30).cumsum(),
    'Time Series Component': np.random.choice(list('ABC'), 30),
})

alt.Chart(ys.reset_index()).mark_line(point=True, strokeWidth=5).encode(
    x="Time:T",
    y="HL:Q",
    color=alt.Color(
        "Time Series Component",
        scale=alt.Scale(scheme="dark2")
    ),
    tooltip=["Time Series Component", "Time", "HL"]
).interactive().properties(
    width=1000,
    height=500
).configure_axis(
    labelFontSize=20,
    titleFontSize=20
).configure_legend(
    orient="right"
).configure_point(
    size=200
)

enter image description here

See https://altair-viz.github.io/user_guide/customization.html for more information about customizing altair visualizations.

Upvotes: 16

Related Questions