wxy01giser commited on
Commit
1be2b0d
·
verified ·
1 Parent(s): 8fbfc04

Update cluster_insight.py

Browse files
Files changed (1) hide show
  1. cluster_insight.py +12 -2
cluster_insight.py CHANGED
@@ -23,6 +23,7 @@ import pickle
23
  from sklearn.feature_extraction.text import TfidfVectorizer
24
  import jieba
25
 
 
26
 
27
  def extract_cluster_keywords_auto(sentences, labels, cluster_id, top_n=3):
28
  """
@@ -198,6 +199,10 @@ def cluster_and_visualize(
198
  marker=dict(size=10, color=point_colors, opacity=0.7),
199
  text=[f"聚类 {l}" for l in labels],
200
  hoverinfo='text',
 
 
 
 
201
  showlegend=False
202
  ))
203
  # 聚类中心
@@ -211,13 +216,18 @@ def cluster_and_visualize(
211
  marker=dict(size=30, color=cluster_colors[i], line=dict(width=2, color='black')),
212
  text=[keyword],
213
  textposition="top center",
214
- textfont=dict(family="SimHei", size=20, color='black'),
215
  showlegend=False
216
  ))
217
 
218
  fig.update_layout(
219
  title="EGISInsight:学生反馈聚类洞察",
220
- font=dict(family="Microsoft YaHei", size=18),
 
 
 
 
 
221
  width=900, height=600,
222
  plot_bgcolor='#F5F5F5',
223
  autosize=False, # 关闭自动缩放
 
23
  from sklearn.feature_extraction.text import TfidfVectorizer
24
  import jieba
25
 
26
+ CHINESE_FONT = "Noto Sans SC" # 思源黑体(跨平台兼容,Plotly 自带)
27
 
28
  def extract_cluster_keywords_auto(sentences, labels, cluster_id, top_n=3):
29
  """
 
199
  marker=dict(size=10, color=point_colors, opacity=0.7),
200
  text=[f"聚类 {l}" for l in labels],
201
  hoverinfo='text',
202
+ hoverlabel=dict(
203
+ font=dict(family=CHINESE_FONT, size=16), # hover 字体适配中文
204
+ bgcolor='white'
205
+ ),
206
  showlegend=False
207
  ))
208
  # 聚类中心
 
216
  marker=dict(size=30, color=cluster_colors[i], line=dict(width=2, color='black')),
217
  text=[keyword],
218
  textposition="top center",
219
+ textfont=dict(family=CHINESE_FONT, size=20, color='black', weight='bold'),
220
  showlegend=False
221
  ))
222
 
223
  fig.update_layout(
224
  title="EGISInsight:学生反馈聚类洞察",
225
+ titlefont=dict(
226
+ family=CHINESE_FONT,
227
+ size=22,
228
+ weight='bold'
229
+ ),
230
+ font=dict(family=CHINESE_FONT, size=18),
231
  width=900, height=600,
232
  plot_bgcolor='#F5F5F5',
233
  autosize=False, # 关闭自动缩放