Plotly Express Stack Ploit

#1

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?

#2

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

#3

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

1 Like
#4

The release is out: v0.1.8

#5

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

#6

Here is the example from https://plotly.express/

#7

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

#8

Ah for stacked bars we have always supported px.bar(...) like this:

#9

Ah perfect!. I tested it for my approach and what I want is to update my graph. So i create a fig with px.bar 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 px.bar 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 px.bar 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 = px.bar(frame1,x='x',color="color",y='y')
print(d.data[0]['x'].shape)
print(d.data[0]['y'].shape)
e = go.FigureWidget(d)
print(e.data[0]['y'])
print(e.data[0]['y'].shape)
print(e.data[0]['x'])
print(e.data[0]['x'].shape)
#10

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

#11

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 px.bar. 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.

#12

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

#13

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.

#14

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 :

#15

what version of pandas are you using?

#16

My pandas version is 0.24.2

#17

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)