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"
)
By default Altair uses a linear mapping between the domain values (MIC) and the range values (pixels). To get a better overview of the data, we can apply a different scale transformation. To change the scale type, we'll set the scale attribute, using the alt. Scale method and type parameter.
Customizing Colors If you don't like the colors chosen by Altair for your scatter plot, you can customize the colors. The default colors can be changed using the scale argument of the Color class, By passing the Scale class to the scale argument.
We can remove the grid lines on x or y-axis by specifying the argument grid=False inside alt. X() or alt. Y() method in the encoding channels.
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
)
See https://altair-viz.github.io/user_guide/customization.html for more information about customizing altair visualizations.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With