Skip to content

Commit

Permalink
feat: rotate long labels in contingency tables
Browse files Browse the repository at this point in the history
Resolves #56
  • Loading branch information
mbelak-dtml committed Nov 1, 2023
1 parent 2502938 commit 30b5f95
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions edvart/report_sections/bivariate_analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -981,12 +981,17 @@ def contingency_table(
square=True,
)
ax.figure.set_size_inches(size_factor * len(table.columns), size_factor * len(table))

ax.set_xticklabels(ax.get_xticklabels(), fontsize=fontsize)

# Set y axis
ax.set_ylabel(ax.get_ylabel(), fontsize=fontsize)
ax.set_yticklabels(ax.get_yticklabels(), rotation=0, fontsize=fontsize)

# Set x axis
xticklabels = ax.get_xticklabels()
x_label_rotation = (
0 if max(len(xticklabel.get_text()) for xticklabel in xticklabels) < 5 else 30
) # rotate if any x tick label is longer than 5 characters
ax.set_xticklabels(xticklabels, fontsize=fontsize, rotation=x_label_rotation)

ax.xaxis.tick_top()
ax.set_xlabel(ax.get_xlabel(), fontsize=fontsize)
ax.xaxis.set_label_position("top")
Expand Down

0 comments on commit 30b5f95

Please sign in to comment.