上传文件至 /
This commit is contained in:
26
q4_1.py
Normal file
26
q4_1.py
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
|
||||||
|
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()
|
||||||
BIN
q4_1_bar.png
Normal file
BIN
q4_1_bar.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 19 KiB |
Reference in New Issue
Block a user