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.

Legend colors missing

See original GitHub issue

I have Vega3 installed and using the latest Jupyter notebook I am attempting to plot a bar chart with a legend. While colors are shown correctly in the chart, the corresponding colors are missing in the legend labels.

alt.Chart(df).mark_bar().encode(
    alt.X('subset:O', axis=alt.Axis(title='Subset')),
    alt.Y('sum(sha256):Q', axis=alt.Axis(title='Number of samples')),
    alt.Color('label:N', scale=alt.Scale(range=["#3333ff", "#ff3333"]), legend=alt.Legend(values=["Cat1", "Cat2"]))
)

Issue Analytics

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

github_iconTop GitHub Comments

1reaction
jakevdpcommented, May 17, 2018

Ah – so you’re setting the legend values to values that are not in your dataset, so there are no associated markers for those values.

If you want your legend to reflect labels that do not exist in your data, the best approach is to transform your data. You can either do this as a preprocessing step (i.e. modify the actual dataframe) or by using a transform within the chart specification. As an example of the latter approach, see this example figure where a column of zeros and ones is mapped to “Male” and “Female” within the chart.

0reactions
mozark24commented, May 17, 2018

Here is a minimal dataframe which can be re-created to produce the problem.

df = pd.DataFrame({'label':[0,0,1,1],
                   'subset':['test','train','test','train'],
                   'sha256':[100000,300000,100000,300000]})
Read more comments on GitHub >

github_iconTop Results From Across the Web

PlotLegend Colors Missing - Mathematica Stack Exchange
I want a PlotLegend with the colors of the graphics. p4 = Plot[y1[t] /. s1, {t, 0, tmax}, PlotRange -> All, PlotStyle ->...
Read more >
Missing legend when specify color using fill in geom_bar ...
Is there a way to add legends back? When I specify the color for each bar, The legend disappeared.
Read more >
The legend box in plot has no colors - MATLAB Answers
The legend box in matlab has no colours. This is the code: x = linspace(0,pi);. y1 = cos(x);. plot(x,y1,'DisplayName','cos(x)'). hold on. y2 =...
Read more >
Missing raster symbology colors in legend on Online Scene
Everything is in the scene correctly, but my slope raster classification colors are not showing in the legend, only the labels. Is this...
Read more >
Legend in excel chart does not show the colors for the data ...
Three series have only one point and they are overlapped using the series overlap feature in formatting. They display fine on the chart....
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