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.

Adding Legend in Selective Lines Chart based on Color and Thickness

See original GitHub issue

Hi,

I have been trying to create Line chart with selectively highlighting few lines. Although I got success in that by using layering but not able to figure out how to plot legend in this case.

Help appreciated !

base = alt.Chart(result1,title='Multivariate, pure factor returns'.upper()).encode(
      x=alt.X('date_str:T', scale=alt.Scale(domain=['2011-12-31','2017-10-31']), 
      axis=alt.Axis(title=''.upper(),format=("%b-%Y"))),
)

chart=alt.layer(
    base.mark_line(color='blue',strokeWidth=0.5).encode(y='Best Price Correlation'),
    base.mark_line(color='red').encode(y='Percent Change YoY')
)

chart

github

Format for result1 is as below

image

And how not to include y axis titles ?

Issue Analytics

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

github_iconTop GitHub Comments

2reactions
Alcampopianocommented, Apr 4, 2019

@ashutosh29

Hi there,

It seems that you are looking to make a line chart with specific colors for each line, and a legend. If that is correct, you may be able to extend from this example:

import altair as alt
from vega_datasets import data

source = data.stocks()

alt.Chart(source).mark_line().encode(
    x='date',
    y='price',
    color=alt.Color('symbol', scale=alt.Scale(range=['red', 'lightgray'], domain=['AAPL', 'GOOG']))
)

visualization

1reaction
ashutosh29commented, Apr 5, 2019

Wondeful, thanks a lot !

Read more comments on GitHub >

github_iconTop Results From Across the Web

Can we add an interactive legend to the interactive line chart ...
See interactive line chart. On click in the legend, increase the thickness of the line, gray-out all other lines, and gray out all...
Read more >
How to Change the Color Coding on a Microsoft Excel Graph ...
Color Your Legend​​ Open Excel's Format Legend pane by right-clicking the legend in a chart and selecting "Format Legend." Click the window's Fill...
Read more >
Video: Customize a line chart - Microsoft Support
Click the chart you want to change. · In the upper-right corner, next to the chart, click Chart Styles. · Click Color and...
Read more >
Add a legend, gridlines, and other markings in Keynote on iPad
Tap Chart, then turn on Legend. Tap the legend to select it, then do any of the following: Change the style of the...
Read more >
Dynamically Highlight Line Chart Series in Power BI - YouTube
In this Power BI tutorial, learn how to dynamically highlight a specific line in a line chart by slicer selection!
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