-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
add stacked grouped bars #4914
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
I see this issue is marked as closed but I'm having trouble tracking resolution. Could you point me in the right direction, please?
|
This issue is actually still open :) |
Is there any update on this issue? |
This issue is going to be worked on in the next couple of months. |
Thanks @nicolaskruchten |
Hello, could you please tell me if this feature is still expected to be available soon? |
We will be working on it in the near future but I can't publicly commit to a timeline at this time. |
Are there any updates on this? |
@RenaudLN or anyone else, can you show us code to produce the figure above or similar? |
@RenaudLN Yes, could you please share the code for your plot? |
@araichev @Alexander-Serov Here is a minimum reproducible example with Python. Note that the offsets are suited to this monthly data and will have to be adjusted with other inputs. import numpy as np
import pandas as pd
import plotly.graph_objects as go
# Create dummy data indexed by month and with multi-columns [product, revenue]
index = pd.date_range("2020", "2021", freq="MS", closed="left")
df = pd.concat(
[
pd.DataFrame(
np.random.rand(12, 3) * 1.25 + 0.25,
index=index,
columns=["Revenue1", "Revenue2", "Revenue3"]
),
pd.DataFrame(
np.random.rand(12, 3) + 0.5,
index=index,
columns=["Revenue1", "Revenue2", "Revenue3"]
),
],
axis=1,
keys=["Product1", "Product2"]
)
# Create a figure with the right layout
fig = go.Figure(
layout=go.Layout(
height=600,
width=1000,
barmode="relative",
yaxis_showticklabels=False,
yaxis_showgrid=False,
yaxis_range=[0, df.groupby(axis=1, level=0).sum().max().max() * 1.5],
# Secondary y-axis overlayed on the primary one and not visible
yaxis2=go.layout.YAxis(
visible=False,
matches="y",
overlaying="y",
anchor="x",
),
font=dict(size=24),
legend_x=0,
legend_y=1,
legend_orientation="h",
hovermode="x",
margin=dict(b=0,t=10,l=0,r=10)
)
)
# Define some colors for the product, revenue pairs
colors = {
"Product1": {
"Revenue1": "#F28F1D",
"Revenue2": "#F6C619",
"Revenue3": "#FADD75",
},
"Product2": {
"Revenue1": "#2B6045",
"Revenue2": "#5EB88A",
"Revenue3": "#9ED4B9",
}
}
# Add the traces
for i, t in enumerate(colors):
for j, col in enumerate(df[t].columns):
if (df[t][col] == 0).all():
continue
fig.add_bar(
x=df.index,
y=df[t][col],
# Set the right yaxis depending on the selected product (from enumerate)
yaxis=f"y{i + 1}",
# Offset the bar trace, offset needs to match the width
# The values here are in milliseconds, 1billion ms is ~1/3 month
offsetgroup=str(i),
offset=(i - 1) * 1000000000,
width=1000000000,
legendgroup=t,
legendgrouptitle_text=t,
name=col,
marker_color=colors[t][col],
marker_line=dict(width=2, color="#333"),
hovertemplate="%{y}<extra></extra>"
)
fig.show() |
Is there any update with this issue? Would be great to have implemented! |
Is there any update on this feature? Looks like it has been asked for in one form or another for 8 years |
@araichev Is this different than multicategory? I recently made a similar chart to the screenshot above `function onlyUnique(value, index, array) { // Example data for the x-axis, normally you would fetch this from your data set let dates = categories.map(c => { let animals = categories.map(c => { dates = dates.filter(onlyUnique); let xDates = []; let xAnimals = []; var yValuesA = xAnimals.map(() => Math.random() * 0.95 + 0.05); var data = [ var layout = { // console.log('data', data); Plotly.newPlot('myDiv', data, layout);` ![]() |
Resolved in #7009. |
We need to permit mixed stacked and grouped bars.
We will implement this with a new
bar.stackgroup
attribute as spec'ed here: #3402The text was updated successfully, but these errors were encountered: