8000 Stacked grouped bar chart by RenaudLN · Pull Request #4486 · plotly/plotly.py · GitHub
[go: up one dir, main page]

Skip to content

Stacked grouped bar chart #4486

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

Closed
wants to merge 8 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
black formatting
  • Loading branch information
RenaudLN committed Jan 20, 2024
commit c8b383a4613be2e4728ba184852c8ca4bebcaa8d
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,17 @@ def get_colors(base_color, n_colors):
return [base_color]

if n_colors == 2:
light = colorsys.hls_to_rgb(hls_tuple[0], min(1, max(0.75, hls_tuple[1] + 0.2)), hls_tuple[2])
light = colorsys.hls_to_rgb(
hls_tuple[0], min(1, max(0.75, hls_tuple[1] + 0.2)), hls_tuple[2]
)
return pyc.sample_colorscale([light, base_color], n_colors)

light = colorsys.hls_to_rgb( 8000 hls_tuple[0], min(1, max(0.8, hls_tuple[1] + 0.2)), hls_tuple[2])
dark = colorsys.hls_to_rgb(hls_tuple[0], max(0, min(0.3, hls_tuple[1] - 0.2)), hls_tuple[2])
light = colorsys.hls_to_rgb(
hls_tuple[0], min(1, max(0.8, hls_tuple[1] + 0.2)), hls_tuple[2]
)
dark = colorsys.hls_to_rgb(
hls_tuple[0], max(0, min(0.3, hls_tuple[1] - 0.2)), hls_tuple[2]
)
return pyc.sample_colorscale([light, base_color, dark], n_colors)

if template is None:
Expand Down Expand Up @@ -125,21 +131,18 @@ def get_colors(base_color, n_colors):
color_discrete_sequence[i % len(color_discrete_sequence)],
n_colors,
)
group_fig = (
bar(
group_df,
color_discrete_sequence=colors,
hover_data=hover_data,
**args,
)
.update_traces(
offsetgroup=str(i),
offset=(i - n_groups / 2) * (group_width + bar_gap) + 1 / 2 * bar_gap,
width=group_width,
legendgroup=group,
legendgrouptitle_text=group,
**{f"{value_axis}axis": f"{value_axis}{i + 1}"},
)
group_fig = bar(
group_df,
color_discrete_sequence=colors,
hover_data=hover_data,
**args,
).update_traces(
offsetgroup=str(i),
offset=(i - n_groups / 2) * (group_width + bar_gap) + 1 / 2 * bar_gap,
width=group_width,
legendgroup=group,
legendgrouptitle_text=group,
**{f"{value_axis}axis": f"{value_axis}{i + 1}"},
)
if fig is None:
fig = group_fig
Expand All @@ -155,9 +158,7 @@ def get_colors(base_color, n_colors):
}
}
)
fig.update_layout(
**{f"{base_axis}axis_type": "category"}
)
fig.update_layout(**{f"{base_axis}axis_type": "category"})
if hover_unified:
fig.update_layout(hovermode="x unified").update_traces(hovertemplate="%{y}")

Expand All @@ -171,5 +172,5 @@ def get_colors(base_color, n_colors):
"stack_group_gap": "Value between 0 and 1. Sets the gap between the stack groups.",
"bar_gap": "Value between 0 and 1. Sets the gap between the bars within each group.",
"hover_unified": "Whether to show the hover in a unified format.",
}
},
)
< 4C81 td class="blob-num blob-num-addition empty-cell">
Original file line number Diff line number Diff line change
Expand Up @@ -4518,28 +4518,31 @@ def test_build_dataframe(self):
assert len(fig7.frames) == n_frames
assert fig6.data[0].geojson == fig1.data[0].geojson


class TestBarStackGroup(NumpyTestUtilsMixin, TestCaseNoTemplate):
data = pd.read_csv(StringIO(
"loc,prod,type,value,err\n"
"L1,P1,R1,4,0.2\n"
"L1,P1,R2,4.5,0.2\n"
"L1,P1,R3,4.5,0.2\n"
"L1,P2,R1,5.6,0.2\n"
"L1,P2,R2,5,0.2\n"
"L1,P3,R1,3.5,0.2\n"
"L1,P3,R2,3.5,0.2\n"
"L1,P3,R3,3.5,0.2\n"
"L2,P1,R1,2,0.2\n"
"L2,P1,R2,2,0.2\n"
"L2,P2,R1,2.5,0.2\n"
"L2,P2,R2,3,0.2\n"
"L2,P3,R2,3.5,0.2\n"
"L3,P1,R1,2,0.2\n"
"L3,P1,R2,2,0.2\n"
"L3,P2,R1,2.5,0.2\n"
"L3,P2,R2,3,0.2\n"
"L3,P3,R2,3.5,0.2\n"
))
data = pd.read_csv(
StringIO(
"loc,prod,type,value,err\n"
"L1,P1,R1,4,0.2\n"
"L1,P1,R2,4.5,0.2\n"
"L1,P1,R3,4.5,0.2\n"
"L1,P2,R1,5.6,0.2\n"
"L1,P2,R2,5,0.2\n"
"L1,P3,R1,3.5,0.2\n"
"L1,P3,R2,3.5,0.2\n"
"L1,P3,R3,3.5,0.2\n"
"L2,P1,R1,2,0.2\n"
"L2,P1,R2,2,0.2\n"
"L2,P2,R1,2.5,0.2\n"
"L2,P2,R2,3,0.2\n"
"L2,P3,R2,3.5,0.2\n"
"L3,P1,R1,2,0.2\n"
"L3,P1,R2,2,0.2\n"
"L3,P2,R1,2.5,0.2\n"
"L3,P2,R2,3,0.2\n"
"L3,P3,R2,3.5,0.2\n"
)
)

def test_simple_stack_group(self):
fig = ff.create_grouped_stacked_bar(
Expand Down Expand Up @@ -4579,7 +4582,12 @@ def test_advanced_stack_group(self):
stackgroup="prod",
stackgroupgap=0.33,
error_y="err",
labels={"loc": "Location", "value": "Revenue", "type": "Type", "prod": "Product"},
labels={
"loc": "Location",
"value": "Revenue",
"type": "Type",
"prod": "Product",
},
hover_name="prod",
category_orders={
"loc": ["L3", "L2", "L1"],
Expand Down
0