Replies: 1 comment 1 reply
-
You probably want The default value for interpolate is import altair as alt
import pandas as pd
import numpy as np
df = pd.DataFrame({'x': np.arange(-10, 10)})
def charter(method):
return alt.Chart(df, title=method).mark_rect().encode(
x=alt.X('x:O',title=None),
color=alt.Color('x:Q',
scale=alt.Scale(
domain=[-10,-5,0,5,9],
range=['red','orange','white','lightblue','darkblue'],
interpolate=method
),
legend=alt.Legend(direction='horizontal', orient='top', title=None)
)
)
methods = ['hcl', 'rgb', 'hsl', 'hsl-long', 'lab', 'hcl-long', 'cubehelix', 'cubehelix-long']
alt.vconcat(*[charter(method) for method in methods]).resolve_scale(color='independent') |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I am using Altair for Python and my current heatmap code uses a redyellowblue color scheme (A) that uses yellow as the middle color. I am trying to edit this color scheme in order to achieve the scheme on (B), which the only difference is replacing yellow with white as the middle color. Does anyone have any idea on how to achieve that in Altair?
The color scheme on (B) was created in R, by using the RdYlBu color pallete (the one with 11 colors) and overwrite the middle (6th color) with white. Then, they increased the number of colors in the pallete to 99, to make the fade look more fluid.
My current code (A):
color=alt.Color('Spline_WW_Diff_Trend:Q', scale=alt.Scale(scheme='redyellowblue',reverse=True, domain=[-3.57,2.270], domainMid=0, clamp=True), legend=alt.Legend(title="Trend"))
I have tried manually setting up the colors using range but got an odd result. I've also used a condition to override the color for the value 0, but it wasn't satisfactory because the numbers neighboring 0 should have a white(ish) color.
Beta Was this translation helpful? Give feedback.
All reactions