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.

Using multiple columns to define "color"

See original GitHub issue

Let’s say I have a dataframe with an x, y, and two categories:

df = pd.DataFrame(dict(
    x=[1,2,3],
    cat1=['red', 'red', 'blue'],
    cat2=['apple', 'apple', 'banana'],
    y=[10,11,12]
))

I’d like a plot with 2 lines: “red,apple” and “blue,banana”, with “red,apple” having two points, and “blue,banana” having 1.

I can do this by combining the two columns into one in the dataframe, but this seems like a very common use case that should be natively supported.

Issue Analytics

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

github_iconTop GitHub Comments

1reaction
lizhoulacommented, Jan 18, 2021

How can I encode color with a column that specifies the color? image I have this column and what to every bar to use this color instead of the auto one.

1reaction
jakevdpcommented, Nov 6, 2019

You can do this with a Calculate Transform; for example:

alt.Chart(df).transform_calculate(
    cat="datum.cat1 + '-' + datum.cat2"
).mark_point().encode(
    x='x:Q',
    y='y:Q',
    color='cat:N'
)

visualization (27)

Read more comments on GitHub >

github_iconTop Results From Across the Web

Example – Multiple Fields on Color - Tableau Help
Follow these steps, using the Sample - Superstore data source, to build a treemap with two fields on Color. Drag Category and Sub-Category...
Read more >
Set background colors for the cells of multiple columns based ...
For columns res1 and res2 , let's say if value content are true s, I'll need to highlight that cell with red background...
Read more >
'Use value as color' option for View column affects multiple ...
This is working as designed. When a column color is set using the "Use value as color" property, the color applies to all...
Read more >
How to define colors for multiple columns/rings in a JavaScript ...
I know how to use the Color Manager Node to define the colors of one column/ring, but then all other columns are colored...
Read more >
Conditional formatting multiple columns by text value
Objective: Change background color using a HEX color code based on cell value for columns PBar_01 to PBar_14. My current solution involves ...
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