Skip to content
Advertisement

How to label the line from transform_regression using Altair?

The code below creates a regression line; however, the legend defaults to labeling the line as “undefined.” How can this regression line be labeled in the legend as “reg-line”?

JavaScript

enter image description here

Advertisement

Answer

Simply add .transform_fold(["reg-line"], as_=["Regression", "y"]).encode(alt.Color("Regression:N")) after mark line

Code should look like

JavaScript

enter image description here

User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement