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.

Specify the color

See original GitHub issue
mv_dict = {'type': ['values', 'values'], 'quantity': [5, 10], 'category': ['mv', 'no_mv']}
df = pd.DataFrame(mv_dict)
alt.Chart(df).mark_bar().encode(
    y='type',
    x='sum(quantity)',
    color='category',
)

With this piece of code, the graph is generated automatically using blue for ‘mv’ and orange for ‘no_mv’

image

Since in some contexts, the color has an implicit connotation…could it be possible to specify what color I want to use for ‘mv’ (e.g. red) and what for ‘no_mv’ (e.g. green)?

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:10 (4 by maintainers)

github_iconTop GitHub Comments

21reactions
afonitcommented, Jun 7, 2018

Here you go:

import altair as alt
import pandas as pd
mv_dict = {'type': ['values', 'values'], 'quantity': [5, 10], 'category': ['mv', 'no_mv']}
df = pd.DataFrame(mv_dict)
alt.Chart(df).mark_bar().encode(
    y='type',
    x='sum(quantity)',
    color=alt.Color('category',
                   scale=alt.Scale(
            domain=['mv', 'no_mv'],
            range=['red', 'green'])))

visualization 2

12reactions
jakevdpcommented, Jun 7, 2018

You can also use alt.Color('category', scale=alt.Scale(scheme=scheme_name)) where scheme_name is a string that matches any of the available Vega color schemes: https://vega.github.io/vega/docs/schemes/#reference

Edit: scheme should be a scale argument

Read more comments on GitHub >

github_iconTop Results From Across the Web

Defining Colors in CSS
There are several different ways to specify colors in CSS. Color Keywords; RGB; RGBA; HSL; HSLA; Hexadecimal. Color Keywords. The first and easiest...
Read more >
Specifying Colors — Matplotlib 3.6.2 documentation
Matplotlib recognizes the following formats to specify a color. ... The colors green, cyan, magenta, and yellow do not coincide with X11/CSS4 colors....
Read more >
Specify Plot Colors - MATLAB & Simulink - MathWorks
Specify Plot Colors. MATLAB ® creates plots using a default set of colors. The default colors provide a clean and consistent look across...
Read more >
<color> - CSS: Cascading Style Sheets - MDN Web Docs
The <color> data type is specified using one of the options listed below. Note: Although <color> values are precisely defined, their actual ...
Read more >
Choose colors in Adobe Photoshop
In the Adobe Color Picker, you choose colors using four color models: HSB, RGB, Lab, and CMYK. Use the Adobe Color Picker to...
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