Announcing Dash Bio 1.0.0 πŸŽ‰ : a one-stop-shop for bioinformatics and drug development visualizations.

Plotly.express area multiple plot error

Hi all

This is my code:

import pandas as pd
import plotly.express as px
df={'x':[1,2,3,4,5],'y1':[1,2,3,4,5],'y2':[2,3,4,5,6],'y3':[3,4,5,6,7]}
df=pd.DataFrame(df)
fig = px.area(df, x="x", y=['y1','y2','y3'])
fig.show()

As you can see my Y data are maximum 7. Why the results in the figure shows wrong values? why the vertical axis (value) do not show the correct values that are defined in above dictionary???

As I understood, ( pandas - Plotly.express Area multiple plots data error - Stack Overflow)
plotly.express.area
creates a stacked area plot, where each filled area corresponds to one column of the input data:

For example, at x = 5 , the stacked area plot reaches y = 18 = 5 + 6 + 7 .

Now the question is that What if I need to fill the area under the function like express.area whitout above problem ?

@Bijan, you can do it this way

df={'x':[1,2,3,4,5],'y1':[1,2,3,4,5],'y2':[2,3,4,5,6],'y3':[3,4,5,6,7]}
df=pd.DataFrame(df)
fig = go.Figure() 
fig.add_scatter(x = df['x'], y=df['y1'], mode='lines',fill='tozeroy', fillcolor='red') 
fig.add_scatter(x = df['x'], y=df['y2'], mode='lines', fill='tonexty',fillcolor='green') 
fig.add_scatter(x = df['x'], y=df['y3'], mode='lines',fill='tonexty',fillcolor='blue') 

fig.show()
1 Like

Thanks @alooksha. That’s the answer :+1: