Reverse/invert color scheme
See original GitHub issueI’d like to use the spectral
color scheme for a heat map I’m working on, but I need to invert the color scheme to more intuitively match my data. (I’m plotting temperature data, and the spectral
scheme defaults to red=low, blue/purple=high.) Is there a way in Altair to reverse/invert the color scheme?
I’ve tried adding reverse=True
to alt.SchemeParams()
based on a note under “Scheme Properties” in the Vega docs, but apparently this feature isn’t supported by Vega-Lite.
The relevant part of my code looks basically like this:
chart = alt.Chart(data).mark_rect().encode(
... ,
color=alt.Color('mean(temperature):Q',
scale=alt.Scale(domain=[lower_bound, upper_bound],
clamp=True,
scheme=alt.SchemeParams(name='spectral', reverse=True))))
Issue Analytics
- State:
- Created 5 years ago
- Reactions:2
- Comments:7 (2 by maintainers)
Top Results From Across the Web
How to Invert the Colors on Your Computer
What Are Inverted Colors? ... Artists use a color wheel, a set of colors arranged in a circle, to help them select hues...
Read more >Invert image (colors) online - Free tool
Invert image is a free online tool, helps to reverse the colors of image, where red color reversed to cyan, green reversed to...
Read more >How To Invert Colors On Windows 10 Easily - MiniTool
Use Magnifier as Color Inverter · You can uncheck Invert colors or press Ctrl + Alt + I to disable inverted colors. ·...
Read more >How to invert colors in Photoshop - Adobe
But if you invert a color image, the resulting photo will have a flipped color scheme. Photoshop will flip every color to its...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
For anyone coming to this with the same problem, I couldn’t get the solution above to work (#2204). However, I was able to get the effect I wanted by passing
reverse=True
in an alt.Scale object to the alt.Color’sscale
parameter:Thank you for the help! Both approaches inverted the color scheme, but I ended up using the
"sort": "descending"
approach because the legend it produced works better for my data. (The"sort": "descending"
approach produces a legend with the highest values at the top, whereas swapping the high and low domain values puts the high value at the bottom of the legend.)