Plotly Express Stacked Area Plot

Is it possible to create a stack plot with plotly express, and maybe to generate a generic stack plot with updating the figure with data?

This isn’t possible yet but we’re likely to add it soon!

This will come out in tomorrow’s release, as px.area :slight_smile:

1 Like

The release is out: v0.1.8

@nicolaskruchten How exactly can I use it to make a stack plot?

Here is the example from

Ah I see, but a stack bar plot is not possible with that, isnt it?

Ah for stacked bars we have always supported like this:

Ah perfect!. I tested it for my approach and what I want is to update my graph. So i create a fig with and convert it to FigureWidget. My data is as follows: I have an x-Axis with 1000 values. Every x value has two y values(one stack bar). And now in my update the y values changes with jupyter widgets.interactive. I want the best performance for updating. For the creation of the figure with the approach I have to double the x value array and create a category array for the x values with corresponding y values. I saw that the creation via reduces the number of x and y values. Why is that? How can I easily update those figures with only setting the y value.Because I have the feeling the more I set new in my update the slower get the update. Do I have to find out how the y values are reorderd and reduced and using this order when setting the y values new? I am using python 3.5 by the way, because I read something about unordered stuff below 3.6.

Here is an example of what I mean:

import ipywidgets as widgets
import pandas as pd
import numpy as np
import plotly_express as px
import plotly.graph_objs as go

frame1 = pd.DataFrame({'y':np.arange(0,1000),'color':np.concatenate([np.random.choice(2,500),np.random.choice(2,500)]),'x':np.concatenate([np.arange(0,500),np.arange(0,500)])})
d =,x='x',color="color",y='y')
e = go.FigureWidget(d)

I’m sorry, I don’t understand the question you’re asking… Does the code above not work for you?

Ok sorry for my bad description of the problem. I just wonder what would be the best way to update the values for my stackplot and why data is missing in the x and y attribute of the figure created by Because I give 1000 values in the figure but after creating and inspecting the x and y attribute of the figure they just have 498, sometimes 512 values.

I’m not seeing the 498/512 issue you’re seeing here…

Ah, maybe I understand… If your “color” is something other than a number, then you will end up with multiple traces, one per color. So if you randomly assign “a” and “b” to “color” then data[0] might have 498 entries and then data[1] will have the other 502 entries. This is deterministic based on your data, however.

I think thats not the problem, because I execute the same code as you are and I got:


Maybe It has something to do with :


what version of pandas are you using?

My pandas version is 0.24.2

Wow this is very strange. Can I get a bit more info about your setup? Python version, PX version, numpy version and operating system? I can’t replicate this at all but it is concerning.

Also, could you share the output of the following command on your data frame? print(frame1.color.dtype.kind, frame1.color.dtype)

Sorry for the really late reply! I dont know what exactly happend but I had a problem with some jupyterlab ipywidget thing. And I reinstalled everything. And now the plotlyexpress barplot thing works exactly how it should! Really strange and also bad because now I cant say what was the origin of the problem

Is it possible to get rid of lines and keep only the shaded area? e.g. by passing mode=‘none’ from the go.Scatter() API?

Yes, you can call .update_traces() on the resulting figure to set any attributes you want, such as .update_traces(line_weight = 0)

1 Like