How to edit lines on a Plotly stacked area chart?

Hello! I have a stacked area chart (image and code below). Is there a way to edit the lines between the stacked areas so that they are white with a width of 0.2? I tried editing the traces but it didn’t work: fig.update_traces(line=dict(color='white', width=0.2)).

fig = px.area(dat, x='date', y='pct', color='category', title='Plot title')

Hi @shortessay ,

As far as I know, I recommend to use graph_objects instead using plotly.express.

Because you can set different color for both line and area (fillcolor) .

"""
Stacked Area Chart with With Line
"""

import plotly.graph_objects as go
import plotly.express as px

# this dataframe have columns : nation, medal and count
df = px.data.medals_long()

# if create using plotly express, you cannot set line and fill color differently
# fig = px.area(df, x='medal', y='count', color='nation', title='Plot title')


# use graph objects instead, to set different color both line and area. 

# color list 
color_list = px.colors.qualitative.Set2

fig = go.Figure()
for idx_nation,nation in enumerate(df["nation"].unique().tolist()):
    # filter df by nation to set different color by nation column
    df_filtered = df[df["nation"] == nation]
    fig.add_trace(go.Scatter(
        x=df_filtered["medal"], y=df["count"],
        mode='lines',
        name=nation,
        # Set the white line
        # Set bigger `width` to see your line color works, maybe 1.5
        line=dict(width=0.2, color='rgb(255, 255, 255)'),
        # set the color of area 
        fillcolor= color_list[idx_nation],
        stackgroup='one' # define stack group
    ))
fig.show()

Hope this help. :slight_smile:

1 Like

@shortwssay
See the link to stackoverflow at the end of this thread:How to make the fill in a Plotly Express Area chart solid (non-transparent)

1 Like