Cecily Mag
Cecily Mag

Reputation: 65

Add three y axis using Altair in Python

I am trying to add the third y axis to the altair plots It's easy to do this with just two y axis.

base = alt.Chart(df).encode(alt.X('time'))

a = base.mark_line(opacity=0.6).encode(alt.Y('price'), color='green')
b = base.mark_point(opacity=0.6).encode(alt.Y('markout'), color='blue')
c = alt.layer(a, b).resolve_scale(y='independent')

But if I use this method adding the third y axis

c = base.mark_line(opacity=0.6).encode(alt.Y('size'), color='lightgrey')
d = alt.layer(a,b,c).resolve_scale(y='independent')

The y axis will overlay on the right. enter image description here

Is there a way to add the third axis on the right of the second? Something like this enter image description here

Upvotes: 0

Views: 535

Answers (1)

Oluwafemi Sule
Oluwafemi Sule

Reputation: 38922

You can offset the axis for the third plot. For example

c = (
    base.mark_line(opacity=0.6)
    .encode(
        alt.Y('size', axis=alt.Axis(offset=40)), 
        color='lightgrey'
    )
)

Upvotes: 1

Related Questions