'How to edit a color scheme?

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?

enter image description here

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.



Solution 1:[1]

I am unable to get your question properly but I assume that you are working on python.

let's keep it very simple.

code

m_tuple = ("Afghanistan", "Angola", "Algeria")
m_dict = {m_tuple[n]: n for n in range(len(m_tuple))}  
for key, value in m_dict.items():
    print(key, value)

output

Afghanistan 0
Angola 1
Algeria 2

Default you have tuple, need to convert into python dictionary that will easily accessible by key and values.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Shakeel Afridi