Files
simulated-examination/q4_1.py
2026-07-06 17:13:04 +08:00

26 lines
732 B
Python

import json
import matplotlib.pyplot as plt
with open("books.json", "r", encoding="utf-8") as f:
data = json.load(f)
books = data["books"]
pub_count = {}
for book in books:
pub_name = book["publisher"]
if pub_name in pub_count:
pub_count[pub_name] += 1
else:
pub_count[pub_name] = 1
publish_names = list(pub_count.keys())
book_nums = list(pub_count.values())
plt.figure(figsize=(10, 6))
plt.bar(pub_count.keys(), pub_count.values())
plt.title("出版社图书数量分布", fontsize=14)
plt.xlabel("出版社名称", fontsize=12)
plt.ylabel("图书数量", fontsize=12)
plt.xticks(rotation=45, ha="right")
plt.tight_layout()
plt.savefig("q4_1_bar.png", dpi=150)
plt.show()