fig = pltfigurefigsize=108ax1 = figadd_subplot211ax1plotpos_kax1set_xlabel正面评论LDA主题数寻优 fontproperties=fontax2 = figadd_subplot212ax2plotneg_kax2set_xlabel负面评论LDA主题数寻优 fontproperties=fontpltshow怎么改让其中的
您可以使用中文字体来解决乱码问题。例如,可以使用SimHei或者FangSong字体来显示中文。以下是一个示例:
import matplotlib.pyplot as plt
from matplotlib.font_manager import FontProperties
font = FontProperties(fname=r"C:\Windows\Fonts\SimHei.ttf", size=14) # 设置中文字体
fig = plt.figure(figsize=(10,8))
ax1 = fig.add_subplot(211)
ax1.plot(pos_k)
ax1.set_xlabel('正面评论LDA主题数寻优', fontproperties=font)
ax2 = fig.add_subplot(212)
ax2.plot(neg_k)
ax2.set_xlabel('负面评论LDA主题数寻优', fontproperties=font)
plt.show()
在上面的示例中,我们使用了SimHei字体来显示中文。您需要将字体文件的路径指定为fname参数的值。如果您的电脑中没有SimHei字体,可以将fname参数的值修改为可用的中文字体文件路径
原文地址: https://www.cveoy.top/t/topic/hot3 著作权归作者所有。请勿转载和采集!