Getting legend for multilayer chart
See original GitHub issueIs it possible to make a legend for such a chart
import altair as alt
import numpy as np
import pandas as pd
x = np.arange(100)
data = pd.DataFrame({'x': x,
'sin(x)': np.sin(x / 5),
'data': np.sin(x / 5) + 0.3*np.random.rand(100)})
line = alt.Chart(data).mark_line(strokeWidth=6, color='orange').encode(
x='x',
y='sin(x)'
)
point = alt.Chart(data).mark_point(color='black').encode(
x='x',
y='data'
)
(line + point)
Issue Analytics
- State:
- Created 5 years ago
- Reactions:3
- Comments:31 (14 by maintainers)
Top Results From Across the Web
Adding legend to layerd chart in altair - python - Stack Overflow
In the resulting chart, I would like to add a legend that shows, that the blue line shows the maximum temperature and the...
Read more >PPT Design Tip: One Legend for Multiple Charts (PowerPoint)
PPT design tip: One legend for multiple charts. Russ Borrelli from eSlide walks you through his tips on how to easily create a...
Read more >Add a legend to a chart - Microsoft Support
Click the chart. · Click Chart Filters Filters next to the chart, and click Select Data. · Select an entry in the Legend...
Read more >Configure Legend - FusionCharts
A legend is a chart element used to display the series name for each dataset, in case of multi-series or combination charts. Legends...
Read more >How to create a creative multi-layer Doughnut Chart in Excel
Move the legend to the right. This makes sense, because just like in the chart, the data points represent an order from the...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top 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
Yes, in newer versions of vega-lite you can set encodings to a constant datum value, which will be used to populate the legend. Altair doesn’t yet support this, though.
In Altair it would probably look something like this (Note that this does not work in the current release):
Thanks! This is indeed a bit hacky:) But I got even a bit closer.
PS: this is probably a different debate (e.g. https://github.com/altair-viz/altair/issues/947); I just found out I could do
instead of
Big kudos points! 👍 Is this documented somewhere or is it a more try and see?