altair icon indicating copy to clipboard operation
altair copied to clipboard

dual axis with overlapping plot not showing ticks

Open fkgruber opened this issue 1 year ago • 2 comments

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')
image

fkgruber avatar Mar 13 '24 13:03 fkgruber

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?

image

joelostblom avatar Mar 13 '24 16:03 joelostblom

oh I see. I will try that thanks

fkgruber avatar Mar 14 '24 12:03 fkgruber