Skip to content

AAA #166

Description

@991-dear

from collections import Counter
import matplotlib.pyplot as plt

解决中文乱码

plt.rcParams["font.sans-serif"] = ["SimHei"]
plt.rcParams["axes.unicode_minus"] = False

预先分好:正面36,中性12,负面12

sentiment_list = [
"正面","正面","正面","正面","正面","正面",
"正面","正面","正面","正面","正面","正面",
"正面","正面","正面","正面","正面","正面",
"正面","正面","正面","正面","正面","正面",
"正面","正面","正面","正面","正面","正面",
"正面","正面","正面","正面","正面","正面",
"中性","中性","中性","中性","中性","中性",
"中性","中性","中性","中性","中性","中性",
"负面","负面","负面","负面","负面","负面",
"负面","负面","负面","负面","负面","负面"
]

统计数量与占比

result = Counter(sentiment_list)
total = len(sentiment_list)
print("宜宾旅游口碑情感统计结果:")
for label, num in result.items():
print(f"{label}:{num} 条,占比 {num/total:.2%}")

绘制情感分布饼图

plt.figure(figsize=(8,6))
plt.pie(result.values(), labels=result.keys(), autopct="%1.2f%%", shadow=True, startangle=90)
plt.title("宜宾蜀南竹海、李庄古镇、五粮液景区游客情感分布")
plt.axis("equal")
plt.show()

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions