You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
40 lines
1.3 KiB
40 lines
1.3 KiB
from stylecloud import gen_stylecloud
|
|
|
|
|
|
class Cloud_shower:
|
|
|
|
def __init__(self):
|
|
pass
|
|
|
|
def to_show(self, sample_danmu_data_frq):
|
|
# 使用stylecloud生成词云
|
|
text_list = []
|
|
for word, freq in sample_danmu_data_frq.items():
|
|
text_list.extend([word] * freq)
|
|
|
|
text = " ".join(text_list)
|
|
gen_stylecloud(
|
|
text=text, # 处理好的文本
|
|
size=1024, # 图片尺寸,越大越清晰
|
|
font_path='msyh.ttc', # 指定中文字体路径(如微软雅黑)
|
|
output_name='ai_danmu_stylecloud.png', # 输出文件名
|
|
icon_name='fas fa-question-circle',
|
|
custom_stopwords=['的', '了', '在', '是', '我', '有', '和', '机'], # 自定义停用词
|
|
palette='colorbrewer.qualitative.Set1_8', # 使用预设配色方案
|
|
# background_color='white', # 背景色
|
|
gradient='horizontal', # 颜色渐变方向
|
|
max_font_size=200, # 最大字体大小
|
|
max_words=500, # 最多显示词数
|
|
)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
import tool.csv_parse as cp
|
|
# 使用示例
|
|
data_map = cp.read_csv_to_list('./result.csv')
|
|
print(data_map)
|
|
|
|
shower = Cloud_shower()
|
|
shower.to_show(data_map)
|
|
print("词云生成完毕,保存为 ai_danmu_stylecloud.png")
|