-
Notifications
You must be signed in to change notification settings - Fork 142
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
[Demo] Fix diverging stacked bar #864
base: main
Are you sure you want to change the base?
Conversation
View the example dashboards of the current commit live on PyCafe ☕ 🚀Updated on: 2024-11-13 14:09:33 UTC Link: vizro-core/examples/dev/ Link: vizro-core/examples/scratch_dev |
fig.update_traces(legendrank=i, selector=({"name": category})) | ||
|
||
|
||
fig.update_xaxes(ticksuffix="%", range=[-80, 80]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This previously worked fine, but now it currently does not work anymore 🤔 It just changes the range of the positive side. Is there another way of doing this now? Without this, the chart is actually misleading. The bars of the negative side look longer than the ones on the positive side, even though the actual value is smaller. They need to share the same axes range, otherwise it's visually confusing.
@@ -63,6 +75,6 @@ def diverging_stacked_bar(data_frame: pd.DataFrame, **kwargs) -> go.Figure: | |||
data_frame=pastries, | |||
x=["Strongly Disagree", "Disagree", "Agree", "Strongly Agree"], | |||
y="pastry", | |||
labels={"value": "Response count", "variable": "Opinion"}, | |||
labels={"value": "", "variable": "", "pastry": ""}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Declutter chart - axes labels and legend titles are redundant here
@@ -303,4 +303,5 @@ def diverging_stacked_bar(data_frame: pd.DataFrame, **kwargs) -> go.Figure: | |||
else: | |||
fig.add_hline(y=0, line_width=2, line_color="grey") | |||
|
|||
fig.update_xaxes(ticksuffix="%", range=[0, 100]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@antonymilne to double-check range
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fig.update_xaxes(ticksuffix="%", range=[0, 100]) |
This is what we want instead of lines 296-299 above. We were right to try and set the range in reverse as [100, 0]
earlier. The problem before was that autorange="reversed"
was overriding that.
fig.update_layout({f"{x_or_y}axis": {"ticksuffix": "%"}})
fig.update_layout({f"{x_or_y}axis2": fig.layout[f"{x_or_y}axis"]})
fig.update_layout(
{
f"{x_or_y}axis": {"domain": [0, 0.5], "range": [100, 0]},
f"{x_or_y}axis2": {"domain": [0.5, 1], "range": [0, 100]},
}
)
I think maximum range of 100 makes more sense than 80 for this plot as a general thing and it looks ok for the example given so I'd go for that. Otherwise we'd need to calculate it dynamically by finding the maximum of x values shown and it's not worth the effort.
@@ -303,4 +303,5 @@ def diverging_stacked_bar(data_frame: pd.DataFrame, **kwargs) -> go.Figure: | |||
else: | |||
fig.add_hline(y=0, line_width=2, line_color="grey") | |||
|
|||
fig.update_xaxes(ticksuffix="%", range=[0, 100]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fig.update_xaxes(ticksuffix="%", range=[0, 100]) |
This is what we want instead of lines 296-299 above. We were right to try and set the range in reverse as [100, 0]
earlier. The problem before was that autorange="reversed"
was overriding that.
fig.update_layout({f"{x_or_y}axis": {"ticksuffix": "%"}})
fig.update_layout({f"{x_or_y}axis2": fig.layout[f"{x_or_y}axis"]})
fig.update_layout(
{
f"{x_or_y}axis": {"domain": [0, 0.5], "range": [100, 0]},
f"{x_or_y}axis2": {"domain": [0.5, 1], "range": [0, 100]},
}
)
I think maximum range of 100 makes more sense than 80 for this plot as a general thing and it looks ok for the example given so I'd go for that. Otherwise we'd need to calculate it dynamically by finding the maximum of x values shown and it's not worth the effort.
Description
Screenshot
Before:
After:
Notice
I acknowledge and agree that, by checking this box and clicking "Submit Pull Request":