Search code examples
plotlyplotly-pythonplotly-express

Remove series border lines from plotly express area chart


px.area shows a line atop each area series. How can I remove it?

The documentation only shows how to remove lines from go.Scatter calls (with mode='none').

Here's an example (notebook), where I'd like to remove the dark blue and red lines atop the light blue and red areas, respectively (to avoid the perception that the red series is nonzero where it stacks atop the blue series):

import plotly.express as px

px.area(y=[[1, 2, 3], [0, 0, 1]])

enter image description here


Solution

  • IIUC this is what you're looking for:

    import plotly.express as px
    
    fig = px.area(y=[[1, 2, 3], [0, 0, 1]])
    

    Before:

    enter image description here

    If you want lines same color as traces:

    for i in range(len(fig['data'])):
      fig['data'][i]['line']['width']=0
    

    enter image description here

    If you want traces same color as lines:

    fig.for_each_trace(lambda trace: trace.update(fillcolor = trace.line.color))
    

    enter image description here