question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Previous solution to flip color scale no longer works

See original GitHub issue

I 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"
        ),
...

wrong_mapping

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]
        ),
...

upside_down_scale

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"
            ),
        ),
...

param_error

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"]
        ),
...

weird_colors

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:closed
  • Created 3 years ago
  • Comments:6

github_iconTop GitHub Comments

2reactions
joelostblomcommented, Feb 23, 2021

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

0reactions
caleb-lindgrencommented, Feb 23, 2021

Yep that does it! Thanks. Is there somewhere in the documentation where I can find this sort of thing?

Read more comments on GitHub >

github_iconTop Results From Across the Web

ggplot2 reverse order of scale_brewer - Stack Overflow
This solution works when using library(RColorBrewer) . (I know OP knows this already, but I wanted to swap ggplot colors and didn't know...
Read more >
Excel's Color Palette Compatibility Issue & Solution
If you're currently going into your previous version palette and modifying colors, you know how time consuming it can be to change the...
Read more >
Color scales in Excel: how to add, use and customize - Ablebits
This tutorial will teach you how to conditionally format cells in Excel using gradient color scales to visually compare values in a range....
Read more >
View and set current colormap - MATLAB colormap - MathWorks
This MATLAB function sets the colormap for the current figure to one of the predefined colormaps.
Read more >
How to reverse a Colormap using Matplotlib in Python?
Now, make the scatter plot by passing the values to plot, c for color, and cmap=reversed for getting the reversed color map. By...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found