问题是ValueError: Only supported for TrueType fonts 但是那个字体文件我路径上面是有的
from wordcloud import WordCloud
from PIL import Image
import numpy as np
import matplotlib.pyplot as plt
import jieba
with open("cloud.txt",encoding="utf-8") as f:
s = f.read()
text = ' '.join(jieba.cut(s))
img = Image.open("img_array.png")
mask = np.array(img)
stopwords = ["我","你","她","的","是","了","在","也","和","就","都","这"]
wc = WordCloud(font_path=r"C:\Windows\Fonts\simhei.ttf",
mask=mask,
width = 1000,
height = 700,
background_color='white',
max_words=200,
stopwords=stopwords).generate(text)
plt.imshow(wc, interpolation='bilinear')
plt.axis("off")
plt.show()
wc.to_file("词云.png")
请问你解决该问题了吗,我也遇到了该问题
请问有谁解决了这个问题吗?
望采纳:
要确保指定的字体文件路径正确,并且文件存在。如果满足以上情况就参考以下我提供的方法。
方法一:你可以尝试使用其他支持的 TrueType 字体文件来替代 simhei.ttf。
plt.rcParams['font.family'] = 'sans-serif'
plt.rcParams['font.sans-serif'] = 'Arial'
方法二:在 Windows 系统上,可以尝试使用 msyh.ttf(微软雅黑字体)或其他常用的中文字体。