Set a diverging color scheme to center on zero in AltairHow to merge two dictionaries in a single expression?Calling an external command in PythonFinding the index of an item given a list containing it in PythonUsing global variables in a functionUnderstanding Python super() with __init__() methodsHow do I sort a dictionary by value?How to make a chain of function decorators?How do I pass a variable by reference?How do I get the number of elements in a list?How do I list all files of a directory?
Did they show Truman doing private things (toilet, etc) when filming him for 24 hours, 7 days a week?
How does the illumination of the sky from the sun compare to that of the moon?
Installing the original OS X version onto a Mac?
!I!n!s!e!r!t! !b!e!t!w!e!e!n!
Installing certbot - error - "nothing provides pyparsing"
Why should I pay for an SSL certificate?
Repurpose telephone line to ethernet
Can I submit a paper computer science conference using an alias if using my real name can cause legal trouble in my original country
Would getting a natural 20 with a penalty still count as a critical hit?
Is there a utility / method to organize trad gear so that each piece is immediately accessible?
Why should P.I be willing to write strong LOR even if that means losing a undergraduate from his/her lab?
Does == actually work the same or different when comparing two primitives vs two Objects in Java?
Virtual destructor moves object out of rodata section
Which basis does the wavefunction collapse to?
The Lucky House
My new Acer Aspire 7 doesn't have a Legacy Boot option, what can I do to get it?
Does git delete empty folders?
Output with the same length always
Adding things to bunches of things vs multiplication
Outer Class can have how many inner class(es)
What causes burn marks on the air handler in the attic?
From France west coast to Portugal via ship?
What happened after the end of the Truman Show?
Check disk usage of files returned with spaces
Set a diverging color scheme to center on zero in Altair
How to merge two dictionaries in a single expression?Calling an external command in PythonFinding the index of an item given a list containing it in PythonUsing global variables in a functionUnderstanding Python super() with __init__() methodsHow do I sort a dictionary by value?How to make a chain of function decorators?How do I pass a variable by reference?How do I get the number of elements in a list?How do I list all files of a directory?
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
How can I go about getting the colour scale to center on zero for a diverging colour scale.
python visualization altair
add a comment |
How can I go about getting the colour scale to center on zero for a diverging colour scale.
python visualization altair
add a comment |
How can I go about getting the colour scale to center on zero for a diverging colour scale.
python visualization altair
How can I go about getting the colour scale to center on zero for a diverging colour scale.
python visualization altair
python visualization altair
edited Mar 27 at 14:12
jakevdp
23.5k4 gold badges42 silver badges62 bronze badges
23.5k4 gold badges42 silver badges62 bronze badges
asked Mar 27 at 13:58
EamonnEamonn
3583 silver badges16 bronze badges
3583 silver badges16 bronze badges
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
One way to do this is to explicitly set the domain to be symmetric:
import numpy as np
import pandas as pd
import altair as alt
df = pd.DataFrame(np.random.randn(100, 3), columns=['x', 'y', 'z'])
alt.Chart(df).mark_point().encode(
x='x',
y='y',
color=alt.Color('z', scale=alt.Scale(scheme='blueorange', domain=[-3, 3]))
)

Ah, perfect! Simple solution. I was hoping there would be a center as in seaborn for example, but this also works, although it's a pain if the values are skewed heavily towards either extreme.
– Eamonn
Mar 27 at 14:14
We do plan to add scale.domainMid to Vega-Lite/Altair, but haven't got the time to do it yet. You can follow the thread here github.com/vega/vega-lite/issues/4542. Contributions are also welcomed. :)
– kanitw
Mar 28 at 5:32
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55379035%2fset-a-diverging-color-scheme-to-center-on-zero-in-altair%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
One way to do this is to explicitly set the domain to be symmetric:
import numpy as np
import pandas as pd
import altair as alt
df = pd.DataFrame(np.random.randn(100, 3), columns=['x', 'y', 'z'])
alt.Chart(df).mark_point().encode(
x='x',
y='y',
color=alt.Color('z', scale=alt.Scale(scheme='blueorange', domain=[-3, 3]))
)

Ah, perfect! Simple solution. I was hoping there would be a center as in seaborn for example, but this also works, although it's a pain if the values are skewed heavily towards either extreme.
– Eamonn
Mar 27 at 14:14
We do plan to add scale.domainMid to Vega-Lite/Altair, but haven't got the time to do it yet. You can follow the thread here github.com/vega/vega-lite/issues/4542. Contributions are also welcomed. :)
– kanitw
Mar 28 at 5:32
add a comment |
One way to do this is to explicitly set the domain to be symmetric:
import numpy as np
import pandas as pd
import altair as alt
df = pd.DataFrame(np.random.randn(100, 3), columns=['x', 'y', 'z'])
alt.Chart(df).mark_point().encode(
x='x',
y='y',
color=alt.Color('z', scale=alt.Scale(scheme='blueorange', domain=[-3, 3]))
)

Ah, perfect! Simple solution. I was hoping there would be a center as in seaborn for example, but this also works, although it's a pain if the values are skewed heavily towards either extreme.
– Eamonn
Mar 27 at 14:14
We do plan to add scale.domainMid to Vega-Lite/Altair, but haven't got the time to do it yet. You can follow the thread here github.com/vega/vega-lite/issues/4542. Contributions are also welcomed. :)
– kanitw
Mar 28 at 5:32
add a comment |
One way to do this is to explicitly set the domain to be symmetric:
import numpy as np
import pandas as pd
import altair as alt
df = pd.DataFrame(np.random.randn(100, 3), columns=['x', 'y', 'z'])
alt.Chart(df).mark_point().encode(
x='x',
y='y',
color=alt.Color('z', scale=alt.Scale(scheme='blueorange', domain=[-3, 3]))
)

One way to do this is to explicitly set the domain to be symmetric:
import numpy as np
import pandas as pd
import altair as alt
df = pd.DataFrame(np.random.randn(100, 3), columns=['x', 'y', 'z'])
alt.Chart(df).mark_point().encode(
x='x',
y='y',
color=alt.Color('z', scale=alt.Scale(scheme='blueorange', domain=[-3, 3]))
)

answered Mar 27 at 14:12
jakevdpjakevdp
23.5k4 gold badges42 silver badges62 bronze badges
23.5k4 gold badges42 silver badges62 bronze badges
Ah, perfect! Simple solution. I was hoping there would be a center as in seaborn for example, but this also works, although it's a pain if the values are skewed heavily towards either extreme.
– Eamonn
Mar 27 at 14:14
We do plan to add scale.domainMid to Vega-Lite/Altair, but haven't got the time to do it yet. You can follow the thread here github.com/vega/vega-lite/issues/4542. Contributions are also welcomed. :)
– kanitw
Mar 28 at 5:32
add a comment |
Ah, perfect! Simple solution. I was hoping there would be a center as in seaborn for example, but this also works, although it's a pain if the values are skewed heavily towards either extreme.
– Eamonn
Mar 27 at 14:14
We do plan to add scale.domainMid to Vega-Lite/Altair, but haven't got the time to do it yet. You can follow the thread here github.com/vega/vega-lite/issues/4542. Contributions are also welcomed. :)
– kanitw
Mar 28 at 5:32
Ah, perfect! Simple solution. I was hoping there would be a center as in seaborn for example, but this also works, although it's a pain if the values are skewed heavily towards either extreme.
– Eamonn
Mar 27 at 14:14
Ah, perfect! Simple solution. I was hoping there would be a center as in seaborn for example, but this also works, although it's a pain if the values are skewed heavily towards either extreme.
– Eamonn
Mar 27 at 14:14
We do plan to add scale.domainMid to Vega-Lite/Altair, but haven't got the time to do it yet. You can follow the thread here github.com/vega/vega-lite/issues/4542. Contributions are also welcomed. :)
– kanitw
Mar 28 at 5:32
We do plan to add scale.domainMid to Vega-Lite/Altair, but haven't got the time to do it yet. You can follow the thread here github.com/vega/vega-lite/issues/4542. Contributions are also welcomed. :)
– kanitw
Mar 28 at 5:32
add a comment |
Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.
Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55379035%2fset-a-diverging-color-scheme-to-center-on-zero-in-altair%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown