How to mark lines based on one column value but set the color based on another column?
See original GitHub issueFirst of all, I would like to thanks the Altair community for posting tutorials/questions online! I learned a lot from the previous posts. But I couldn’t figure out how to color the line series based on the value of another column. A simple example is let’s say I want to make a scatter plot of property1 and property2 from the multi-dimension data set df, and I would like to color the points based on “legend_value”, but also want to connect the points from same “obj” (plotted with different shapes). How can I make the lines has the same color as the scattered points in this plot?
Thanks in advance!!!
df = pd.DataFrame({'Obj':['a','a','a','a','b','b','b','c','c','c','d','d'],
'property1':[1,2,3,4,7,8,9,4,5,6,5,6],
'property2':[0.1,0.2,0.3,0.4,0.35,0.4,0.45,0.8,1,1.2,0.5,0.8],
'legend_value':[1,1,1,1,2,2,2,1,1,1,3,3]})
display(df)
scatter = alt.Chart(df).mark_point().encode(
alt.X('property1:Q', scale=alt.Scale(zero=False)),
alt.Y('property2:Q', scale=alt.Scale(zero=False)),
shape=alt.Shape('Obj:N',legend=None),
color=alt.Color('legend_value:Q',scale=alt.Scale(scheme='rainbow')),
opacity=alt.value(0.8)
)
scatter_objectline = alt.Chart(df).mark_line().encode(
alt.X('property1:Q',scale=alt.Scale(zero=False)),
alt.Y('property2:Q',scale=alt.Scale(zero=False)),
color=alt.Color('Obj:N',legend=None),
opacity=alt.value(0.2)
)
scatter+scatter_objectline
Issue Analytics
- State:
- Created 2 years ago
- Comments:7 (4 by maintainers)
Top Results From Across the Web
Apply Conditional Formatting Based on Another Column in ...
Click on the Format button (to specify the formatting in which you want the names to be highlighted) · Select the formatting (I...
Read more >Excel: Change the row color based on cell value - Ablebits
Click the "Format…" button and switch to Fill tab to choose the background color. If the default colors do not suffice, click the...
Read more >Excel Conditional Formatting Entire Row Based on Cell Value
In the New Formatting Rule dialog box, click the Format button. In the Format Cells dialog box, select the formatting options that you...
Read more >Apply conditional formatting based on values in another column
1. Select the column cells you will highlight (here I select range B2:B13), and then click Home > Conditional Formatting > New Rule....
Read more >Use Conditional Formatting to Highlight a Row or Column
Conditional Formatting is a feature in Excel that allows us to change the format of cells based on a set of rules or...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Awesome! I’ll close this issue; feel free to reopen if you run into another problem with this.
ohhh that makes sense and the output is perfect!! Thank you so much for your patience and the continued help!!