How to make comparison line in Line plots?

image

The bold line is current periods
The faded line is previous periods
(for comparison purposes)

I’m trying to reproduce a plot that look like the attached image with line chart, but not sure how? If I add another plot, it would just add another line that go behind the main line.

Could anyone help me please? Thanks a bunch

Hi @eddiethinhvuong,

You can use the width and color attribute of the line property of go.Scatter() to customize the design of marker as in your example.

Here’s a small example to get you started :

import plotly.graph_objects as go

new_data = [40,22,60,35,24,47,35,17]
old_data = [15,13,22,9,18,31,12,23]
date=["2021-07-17", "2021-07-19", "2021-07-21", "2021-07-23", "2021-07-25", "2021-07-27", "2021-07-29", "2021-07-31"]

fig = go.Figure()
fig.add_trace(
    go.Scatter(
        x=date,
        y=new_data,
        mode='lines',
        line=dict(color='navy', width=2.5),
        name='New Sales'
    )
)
fig.add_trace(
    go.Scatter(
        x=date,
        y=old_data,
        mode='lines',
        line=dict(color='grey', width=1.5),
        name='Old Sales',
    )
)
fig.update_layout(plot_bgcolor='white')

fig.show()

While you’re at it, check out the other examples from the docs page - Line Charts | Python | Plotly

1 Like

thank you very much!

1 Like