Leo
Leo

Reputation: 1168

Make altair scatterplot assign different colours instead of shades of the same colour

I want to replicate this image from altair generated with this code from the examples:

alt.Chart(source).mark_circle(size=60).encode(
x='Vth',
y='mob',
color='Thickness',
tooltip=['Temperature', 'Thickness']
).interactive()e
source = Table_3

Altair example plot

However my dataset choice for colour is numerical: Table_3.head()

this is the code i Have:

source = Table_3

alt.Chart(source).mark_circle(size=60).encode(
    x='Vth',
    y='mob',
    color='Thickness',
    tooltip=['Temperature', 'Thickness']
).interactive()

This causes altair to give me shades of the same colour. i want it to divide it like in the example:

My plot

Upvotes: 1

Views: 71

Answers (1)

kanitw
kanitw

Reputation: 892

You can tell Altair that the number is in fact nominal, not quantitative by adding :N to your "Thickness" field.

alt.Chart(source).mark_circle(size=60).encode(
    x='Vth',
    y='mob',
    color='Thickness:N',
    tooltip=['Temperature', 'Thickness']
).interactive()

Upvotes: 1

Related Questions