Skip to content

Commit 8efa93c

Browse files
committed
contrib_graph: fix layout warnings and improve subplot spacing
The monthly activity heatmap and pie chart legend were overlapping, making both unreadable. Additionally, matplotlib's tight_layout() generated warnings about incompatible axes due to the pie chart legend being positioned outside normal subplot bounds. Switch from tight_layout() to constrained_layout which properly handles elements positioned outside axes bounds. This modern matplotlib approach automatically calculates optimal spacing without manual hspace/wspace parameters. Additional improvements: - Truncate long contributor names in heatmap to 20 chars max - Reduce heatmap y-axis label font size to 9pt - Adjust pie chart legend position slightly right (bbox_to_anchor 1.05) This eliminates the UserWarning and ensures all graph elements are clearly readable without overlap. Generated-by: Claude AI Signed-off-by: Luis Chamberlain <[email protected]>
1 parent 2651ab3 commit 8efa93c

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

scripts/contrib_graph.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -250,19 +250,16 @@ def create_contribution_graphs(
250250
title_suffix = " (All Time)"
251251

252252
# Create figure with multiple subplots and better styling
253-
fig = plt.figure(figsize=(24, 16), facecolor="#f8f9fa")
253+
fig = plt.figure(figsize=(24, 16), facecolor="#f8f9fa", constrained_layout=True)
254254
gs = fig.add_gridspec(
255255
3,
256256
3,
257257
height_ratios=[1, 1, 1.1],
258-
hspace=0.35,
259-
wspace=0.3,
260258
)
261259
fig.suptitle(
262260
f"kdevops Contribution Analysis{title_suffix}",
263261
fontsize=24,
264262
fontweight="bold",
265-
y=0.985,
266263
color="#2c3e50",
267264
)
268265

@@ -386,7 +383,7 @@ def create_contribution_graphs(
386383
legend_labels,
387384
title="Contributors",
388385
loc="center left",
389-
bbox_to_anchor=(1, 0, 0.5, 1),
386+
bbox_to_anchor=(1.05, 0, 0.5, 1),
390387
fontsize=10,
391388
title_fontsize=11,
392389
frameon=True,
@@ -441,7 +438,12 @@ def create_contribution_graphs(
441438
]
442439
ax3.set_xticklabels([month_names[m - 1] for m in months])
443440
ax3.set_yticks(range(len(top_contributors)))
444-
ax3.set_yticklabels(top_contributors)
441+
# Truncate long contributor names to prevent overlap
442+
truncated_names = [
443+
name if len(name) <= 20 else name[:17] + "..."
444+
for name in top_contributors
445+
]
446+
ax3.set_yticklabels(truncated_names, fontsize=9)
445447
ax3.set_title(
446448
"Monthly Activity Heatmap",
447449
fontweight="bold",
@@ -1033,8 +1035,6 @@ def create_contribution_graphs(
10331035
color="#7f8c8d",
10341036
)
10351037

1036-
fig.tight_layout(rect=[0, 0, 1, 0.97], pad=2.5)
1037-
10381038
# Ensure output directory exists and save the plots
10391039
os.makedirs("docs/contrib", exist_ok=True)
10401040
png_file = f"docs/contrib/{output_base}.png"

0 commit comments

Comments
 (0)