Skip to content

Commit c96813d

Browse files
committed
Fix matplotlib backend issue in stripplot for Windows CI
- Changed from plt.figure() to plt.subplots() to avoid Tkinter dependency - This prevents '_tkinter.TclError: Can't find a usable tk.tcl' on Windows CI - The Agg backend is already set but plt.figure() still tried to use TkAgg
1 parent f55f6b5 commit c96813d

File tree

1 file changed

+14
-12
lines changed

1 file changed

+14
-12
lines changed

llm_stylometry/visualization/stripplot.py

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
import pandas as pd
44
import seaborn as sns
5+
import matplotlib
6+
matplotlib.use('Agg') # Use non-interactive backend
57
import matplotlib.pyplot as plt
68
import numpy as np
79
from pathlib import Path
@@ -62,9 +64,9 @@ def generate_stripplot_figure(
6264
# Define author order to match all_losses figure
6365
author_order = ["Baum", "Thompson", "Austen", "Dickens", "Fitzgerald", "Melville", "Twain", "Wells"]
6466

65-
# Create figure
66-
plt.figure(figsize=figsize)
67-
ax = sns.stripplot(
67+
# Create figure using subplots to avoid backend issues
68+
fig, ax = plt.subplots(figsize=figsize)
69+
sns.stripplot(
6870
data=strip_df,
6971
x="Training Author",
7072
y="Loss",
@@ -79,26 +81,26 @@ def generate_stripplot_figure(
7981
)
8082

8183
# Remove title as requested
82-
# plt.title(
84+
# ax.set_title(
8385
# "Loss values: training author vs. other authors",
8486
# fontsize=16,
8587
# pad=10,
8688
# )
87-
plt.xlabel("Training author", fontsize=14)
88-
plt.ylabel("Loss", fontsize=14)
89-
plt.xticks(fontsize=12)
90-
plt.yticks(fontsize=12)
89+
ax.set_xlabel("Training author", fontsize=14)
90+
ax.set_ylabel("Loss", fontsize=14)
91+
ax.tick_params(axis='x', labelsize=12)
92+
ax.tick_params(axis='y', labelsize=12)
9193

9294
# Remove top and right spines
9395
sns.despine(ax=ax, top=True, right=True)
9496

9597
# Add legend to top left without title and box outline
96-
plt.legend(fontsize=12, title=None, loc='upper left', frameon=False)
98+
ax.legend(fontsize=12, title=None, loc='upper left', frameon=False)
9799

98-
plt.tight_layout()
100+
fig.tight_layout()
99101

100102
# Save if path provided
101103
if output_path:
102-
plt.savefig(output_path, bbox_inches="tight", format="pdf")
104+
fig.savefig(output_path, bbox_inches="tight", format="pdf")
103105

104-
return plt.gcf()
106+
return fig

0 commit comments

Comments
 (0)