This snippet:
chart = alt.Chart(df).mark_point(filled=True).encode(
alt.X('Goals Conceded:Q'),
alt.Y('Goals:Q'),
alt.Size('Goals:Q', legend=None, scale=alt.Scale(range=[0, 1500])),
alt.Color('Color', legend=None, scale=None),
tooltip = [alt.Tooltip('For Team:N'),
alt.Tooltip('Goals:Q'),
alt.Tooltip('Goals Conceded:Q')]
).properties(
width=800,
height=600
)
Plots:
Now I would like to manually add a line, where x = y, in order to get the following result:
How can I do this?
You could add a dummy line:
line = pd.DataFrame({
'Goals Conceded': [0, 2],
'Goals': [0, 2],
})
line_plot = alt.Chart(line).mark_line(color= 'red').encode(
x= 'Goals Conceded',
y= 'Goals'.
)
chart + line_plot
I don't have your dataset, so below is an example mostly borrowed from Altair Example Gallery:
import pandas as pd
import altair as alt
from vega_datasets import data
source = data.iris()
iris_plot = alt.Chart(source).mark_circle().encode(
alt.X('sepalLength'),
alt.Y('sepalWidth'),
color='species',
size='petalWidth'
)
line = pd.DataFrame({
'sepalLength': [0, 5],
'sepalWidth': [0, 5],
})
line_plot = alt.Chart(line).mark_line(color= 'red').encode(
x= 'sepalLength',
y= 'sepalWidth',
)
iris_plot + line_plot
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