You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: doc/python/bar-charts.md
+86Lines changed: 86 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -589,6 +589,92 @@ fig.update_layout(
589
589
)
590
590
```
591
591
592
+
### Using a scatterplot to wrap long bars into multiple columns
593
+
594
+
This bar-style pictogram allows readers to focus on the relative sizes of smaller entities by wrapping the bar for largest entries into multiple columns. You could make it even more of a pictogram by using fontawesome to replace the square markers we use below with icons like mortar boards for students.
595
+
596
+
```
597
+
import plotly.graph_objects as go
598
+
import pandas as pd
599
+
600
+
#TODO: make the results and the code compellingly clear, terse, and well designed; for example, make sure all the variable names are descriptive
601
+
#TODO: when we're happy, remove print statements
602
+
#TODO: consider adding the value for each group either above its section or to its title
#text=[category] * (y_end - y_start), # Hover text
633
+
hoverinfo="text"
634
+
))
635
+
tick_locations += [x_start+ (col)/2]
636
+
x_start += col+1+columns_between_units
637
+
print(f"{tick_locations=}")
638
+
639
+
# Update layout for better visualization
640
+
fig.update_layout(
641
+
title=title,
642
+
xaxis=dict(
643
+
tickvals=tick_locations,
644
+
ticktext=list(data.keys()),
645
+
tickangle=-45,
646
+
showgrid=False
647
+
),
648
+
#TODO: HIDE THE Y-AXIS? OR ENUMERATE IT IN "NATURAL UNITS" -- so count
649
+
yaxis=dict(
650
+
title="Units",
651
+
showgrid=False,
652
+
showline=False,
653
+
zeroline=False
654
+
),
655
+
#TO DO: SHOW THE LEGEND, BUT JUST FOR ONE TRACE; LABEL IT WITH SOMETHING LIKE "EACH ICON REPRESENTS {units_per_icon} {Y_VARNAME}"
656
+
showlegend=False,
657
+
#setting the width implicitly sets the amount of space between columns within groups and it's desirable to keep those columns close but not too close
658
+
#TODO: set the width to a value that makes the spacing between columns reasonable; try it as a function of the number of columns of data, number of columns left blank as spacers, the icon size; and the left and right margins
659
+
# there's no right answer; but some answers will look a lot better than others; I'm guessing that roughly 2-3 times as many px as we fill with icons might be good
"University of Mary Washington": 3611, #https://www.usnews.com/best-colleges/university-of-mary-washington-3746#:~:text=Overview,campus%20size%20is%20234%20acres.
0 commit comments