SciPost Code Repository

Skip to content
Snippets Groups Projects
Commit b0e7f629 authored by George Katsikas's avatar George Katsikas :goat:
Browse files

style(graphs): :lipstick: rotate bar labels if exceeding width

parent beed83a1
No related branches found
No related tags found
No related merge requests found
...@@ -302,7 +302,14 @@ class BarPlot(PlotKind): ...@@ -302,7 +302,14 @@ class BarPlot(PlotKind):
match self.options.get("direction", "vertical"): match self.options.get("direction", "vertical"):
case "vertical": case "vertical":
ax.bar(groups, vals) ax.bar(groups, vals)
ax.set_xticklabels(groups, rotation=45, ha="right") # Compare the width of the bars to the width of the labels
# Rotate the labels if they are wider than the bars
labels_overflow_bar = any(
label.get_window_extent().width > bar.get_window_extent().width
for label, bar in zip(ax.get_xticklabels(), ax.patches)
)
if labels_overflow_bar:
ax.set_xticklabels(groups, rotation=45, ha="right")
case "horizontal": case "horizontal":
ax.barh(groups, vals) ax.barh(groups, vals)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment