Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Why is "white" doesn't show as white? #2258

Closed
ma-sadeghi opened this issue Aug 7, 2020 · 2 comments
Closed

Why is "white" doesn't show as white? #2258

ma-sadeghi opened this issue Aug 7, 2020 · 2 comments
Labels

Comments

@ma-sadeghi
Copy link

The following code snippet

temp = alt.Chart(source).mark_rect().encode(
    x=alt.X('x:O', sort=alt.EncodingSortField('y', order='descending')),
    y=alt.Y('y:O', sort=alt.EncodingSortField('y', order='descending')),
    color=alt.Color('z:Q', scale=alt.Scale(range=["white", "green"]))
).configure_scale(
    bandPaddingInner=0.1
)

produces the following heatmap:
image
Is there a way to force altair to show "white" as actual "white"?

@jakevdp
Copy link
Collaborator

jakevdp commented Aug 7, 2020

If you want specific values to be exactly white (rather than just on a linear scale that starts at white), you can specify multiple domain and range values to create a piecewise linear scale. For example:

import altair as alt
import pandas as pd

x, y = np.meshgrid(range(-5, 5), range(-5, 5))
z = 20 * np.random.random(x.shape)
source = pd.DataFrame({'x': x.ravel(),
                       'y': y.ravel(),
                       'z': z.ravel()})


alt.Chart(source).mark_rect().encode(
    x=alt.X('x:O', sort=alt.EncodingSortField('y', order='descending')),
    y=alt.Y('y:O', sort=alt.EncodingSortField('y', order='descending')),
    color=alt.Color('z:Q', scale=alt.Scale(domain=[0, 2, 20], range=["white", "white", "green"]))
).configure_scale(
    bandPaddingInner=0.1
)

visualization (32)

@joelostblom
Copy link
Contributor

@ma-sadeghi I am going through Altair issues to find those that have been resolved and can be closed. It looks to me like this issue has been solved so I am closing it, but please feel free to reopen and add a comment if there is something you don't think is resolved yet.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants