altair
altair copied to clipboard
dual axis with overlapping plot not showing ticks
I would like to have 2 y axis where the units are different. However, it seems altair is removing the ticks of the second y axis. Probably because the plot is overlapping
is there a way around this?
import altair as alt
from vega_datasets import data
source = data.cars()
base = alt.Chart(source).encode(x='year(Year):T')
line_A = base.mark_line(color='#5276A7').encode(
alt.Y('average(Horsepower):Q').axis(titleColor='#5276A7',title='Horsepower')
)
line_B = base.mark_line(color='#F18727').encode(
alt.Y('average(Horsepower)/100:Q').axis(title="Percentage",titleColor='#F18727')
)
alt.layer(line_A, line_B).resolve_scale(y='independent')
It's because you can't do the computation inside the encoding, is need to be in a transform_calculate (only some aggregate computation are supported directly in the encoding string). If you remove /100 you get this which sounds like what you want?
oh I see. I will try that thanks