How to do and px.area UNSTACKED plots, similar to px.line?

I have a dummy data looking like this. I was satisfied when I plotted in with px.line like this:

df_grp = pd.read_csv('dummy_day_temp_humidity.txt')
px.line(df_grp, x='temperature', y='humidity', color='day')

But then I decided to make a bar chart out of it, using the same code I only substituted .line for .bar:, x='temperature', y='humidity', color='day')

But this resulted in a plot, where the bars are stacked additively on top of each, e.g. making the humidity for Thur no longer =1, but ~3.8 and analogously for the other days.

The same happened for px.area. My questions:

1.) How can I unstack (un-accumulate) the values on the y-axis in px.line and px.area for the different days? Can I make the bars/areas semi-transparent, so that the ones in the background shine through (something like the alpha-value in matplotlib)?

2.) Another thing that I would like is to have this displayed with the same x and y data in a ridgeline plot, the depth dimension being the days. Is this possible? I have only seen Ridgeline plots to work in plotly when you use plotly.violin, I tried it with px.line and all the tracks ended up overlapping each other into 1 track, as you can read in my post here

Hi @NeStack
Try this inside your…):


Let me know if it works.

@adamschroeder Thanks, this did what I wanted, it looks now like this:

I also found the keyword to order the bars by increasing y-value, so that a higher one doesn’t sit on top of a shorter one and the bar colours match the legend colours: category_orders={}. For the sake of better contrast I decreased also the y-range and set the opacity to 1. I am now satisfied with the look, the results is:, x='temperature', y='humidity', color='day',barmode='overlay', opacity=1, range_y=[0.86,1.0], category_orders={"day": ["Thur", "Sun", "Sat", "Fri"]})

But, @adamschroeder , can you answer my question 2): Can I make a ridgeline plot out of this?

Hi @NeStack
Yes, I think that’s possible. Plotly has good documentation on this here.

Hello, it is possible to un-stack the values for area plot (px.area)? Similar to the overlay mode for barplot? (barmode=overlay)?

Stacked chart is working as intended but I would like to see the data in an area plot overlaid on top of each other.


I would like to know that as well, how to unstack the values for area plot (px.area).

1 Like