Previous solution to flip color scale no longer works
See original GitHub issueI have the same problem presented in #1068, but the solution given there no longer works. I am using the “redblue” diverging color scheme, and I want to flip it so that red corresponds to higher values and blue corresponds to lower values. (Unfortunately there’s no “bluered” color scheme in Vega.)
Here is what I’m currently getting (colors not mapped the way I want):
...
color=alt.Color(
"mean_expr:Q",
scale=alt.Scale(
scheme="redblue"
),
...
As suggested in #1068, you can kind of fix things by reversing the domain. However, this doesn’t solve the problem, because the color legend is still upside down, even though the colors are now mapped to the correct values:
...
color=alt.Color(
"mean_expr:Q",
scale=alt.Scale(
scheme="redblue",
domain=[1, -1]
),
...
The solution given previously was to pass sort="descending"
to the alt.SchemeParams
object, but this no longer works. Based on https://github.com/vega/vega-lite/issues/4116, it looks like this was due to some change in Vega-Lite.
...
color=alt.Color(
"mean_expr:Q",
scale=alt.Scale(
scheme=alt.SchemeParams(
name="redblue",
sort="descending"
),
),
...
Based on #268, I did try passing the desired colors to the range
parameter of alt.Color
, but because the data are continuous, not discrete, that made just it look weird:
...
color=alt.Color(
"mean_expr:Q",
scale=alt.Scale(
domain=[-1, 0, 1],
range=["blue", "white", "red"]
),
...
I also tried reversing the domain, and then using the direction
and orient
parameters for alt.Legend
to print the color legend right side up instead of upside down, but all the argument combinations I tried passing didn’t have any effect, for some reason–the color legend was printed the same every time.
Is there a replacement for the sort="descending"
option that will produce the same results–that is, invert the color scale mapping, but not print the scale upside down?
Issue Analytics
- State:
- Created 3 years ago
- Comments:6
Top GitHub Comments
Hmmm I don’t think there is a section about it, it is only mentioned in the API reference from what I can see. I opened #2418
Yep that does it! Thanks. Is there somewhere in the documentation where I can find this sort of thing?