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.

Color and Shape Legends Not Combined in Line Chart or Multiple Charts

See original GitHub issue

Code to reproduce:

In line chart:

df = pd.DataFrame(
    data=[[0, 10, "a"], [1, 20, "a"], [0, 15, "b"], [1, 25, "b"]],
    columns=["x", "y", "c"]
)
alt.Chart(df).mark_line().encode(
    x="x",
    y="y",
    color="c",
    shape="c"
)

image

Multi Charts:

df = pd.DataFrame(data=[[0, 10, "a"], [1, 20, "a"], [0, 15, "b"], [1, 25, "b"]], columns=["x", "y", "c"])
points = alt.Chart(df).mark_point().encode(x="x", y="y", color="c", shape="c")
lines = alt.Chart(df).mark_line().encode(x="x", y="y", color=alt.Color("c", legend=None))
points + lines

image

Expected behaviour

The legend should be like this: image

Issue Analytics

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

github_iconTop GitHub Comments

3reactions
jakevdpcommented, Jan 7, 2020

These are probably questions to raise in the Vega-Lite forums.

One note: the last chart will work as expected if you use a detail encoding as well, which controls how data is grouped without adding a visual attribute:

alt.Chart(source).mark_line().encode(
    x='x:Q',
    y='values:Q',
    color='operation:N',
    shape='shifted:N',
    detail='shifted:N'
)

visualization (38)

0reactions
joelostblomcommented, Mar 23, 2022

For reference, the corresponding Vega-Lite issue is here https://github.com/vega/vega-lite/issues/5996

Read more comments on GitHub >

github_iconTop Results From Across the Web

Tableau Tutorial - Combining color / shape legends into one ...
Occasionally, I will put a dimension on both the color and shape cards to increase the contrast to make a scatter plot easier...
Read more >
Vary the colors of same-series data markers in a chart
Set varying colors of data markers (bars, columns, lines, pie or doughnut slices, dots, and other shapes) automatically in an Office chart.
Read more >
Combine legends for color and shape into a single legend
Currently I have 2 legends, one for the colors and one for the two shapes. How can I combine them into a single...
Read more >
A Complete Guide to Line Charts | Tutorial by Chartio
The ability to plot multiple lines also provides the line chart a special use case where it might not usually be selected. Normally,...
Read more >
Be Awesome in ggplot2: A Practical Guide to be Highly Effective
Geometry corresponds to the type of graphics (histogram, box plot, line plot, ... Point shapes, colors and size; Add text annotations to a...
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