结果
数据
{“collect_number”:360,“headline”:“钻石城酒店高级 双床房”,“grade”:4.2,“text”:“1室0厅3人1床”,“money”:344.0},
{“collect_number”:89,“headline”:“钻石城酒店豪华 双床房”,“grade”:5.0,“text”:“1室0厅3人1床”,“money”:388.0},
{“collect_number”:29,“headline”:“是隆太空旅舍独立 三人房”,“grade”:5.0,“text”:“1室0厅3人2床”,“money”:348.0},
{“collect_number”:28,“headline”:“旅行者旅舍三人房”,“grade”:5.0,“text”:“1室0厅3人2床”,“money”:392.0},
{“collect_number”:21,“headline”:“迈阿密酒店家庭 套房”,“grade”:5.0,“text”:“1室0厅3人2床”,“money”:365.0},
{“collect_number”:15,“headline”:“康帕斯酒店集团素坤逸娜娜皇家象牙酒店豪华大床房 大床房”,“grade”:4.6,“text”:“1室1厅2人1床”,“money”:369.0},
{“collect_number”:10,“headline”:“罗夫特尔站旅舍2 床女生宿舍床位房”,“grade”:5.0,“text”:“1室0厅1人1床”,“money”:381.0},
{“collect_number”:9,“headline”:“曼谷市中心奢华大楼中文服務04奢华 大床房”,“grade”:4.8,“text”:“1室0厅2人1床”,“money”:346.0},
{“collect_number”:7,“headline”:“尼古窝曼谷民宿豪华地中海阳台 O 大床房”,“grade”:4.9,“text”:“1室0厅2人1床”,“money”:308.0},
{“collect_number”:2,“headline”:“是隆太空旅舍独立 双床房”,“grade”:5.0,“text”:“1室0厅2人2床”,“money”:305.0},
{“collect_number”:1,“headline”:“尼古窝曼谷民宿粉色浪漫mona E 大床房”,“grade”:5.0,“text”:“1室0厅2人1床”,“money”:333.0},
{“collect_number”:0,“headline”:“班萨拜拉玛四世民宿景观单卧室”,“grade”:5.0,“text”:“1室1厅3人2床”,“money”:384.0},
代码
import matplotlib.pyplot as plt
import re
import numpy as np
# todo:文本部分文件
# {"collect_number":360,"headline":"钻石城酒店高级 双床房","grade":4.2,"text":"1室0厅3人1床","money":344.0}
# {"collect_number":360,"headline":"钻石城酒店高级 双床房","grade":4.2,"text":"1室0厅3人1床","money":344.0}
# {"collect_number":89,"headline":"钻石城酒店豪华 双床房","grade":5.0,"text":"1室0厅3人1床","money":388.0}
# {"collect_number":29,"headline":"是隆太空旅舍独立 三人房","grade":5.0,"text":"1室0厅3人2床","money":348.0}
from numpy import double
plt.rcParams['font.sans-serif']=['SimHei']
plt.rcParams['axes.unicode_minus'] = False
open = open(r"G:\Java\IDEA 程序\程序\Spark\src\test\scala\spark\hotel_MAX.json\a.json", 'r', encoding="utf-8")
text = open.read()
collect_number = re.findall(r'"collect_number":(.*?),', text)
headline = re.findall(r'"headline":"(.*?)",', text)
grade = re.findall(r'"grade":(.*?),', text)
configuration = re.findall(r'"text":"(.*?)",', text)
money = re.findall(r'"money":(.*?)},', text)
x = np.arange(len(headline))
bottom_x = x.copy()
collect_number = list(map(int, collect_number))
grade = list(map(double, grade))
money = list(map(double, money))
# one_subplot
plt.figure(figsize=[10, 7])
plt.style.use("ggplot")
plt.suptitle("ShiZhan_Hotel")
plt.subplot(221)
plt.title("collect_number")
plt.bar(x, collect_number,color="g")
plt.ylabel("collect_number")
# collect_number:数据标签
for x, y in zip(x, collect_number):
plt.text(x, y, "%s" % y, ha="center")
# collect_number:文本
x = 0.55
y = 0.85
for i in range(len(headline)):
plt.figtext(x,y,"%s:"%i+headline[i])
y -= 0.03
# two_subplot
x = np.arange(len(money))
plt.subplot(224)
plt.title("money")
plt.bar(x,money)
plt.ylim(200,500)
plt.xlabel("number")
plt.ylabel("money")
for x,y in zip(x,money):
if x==5:
y += 30
plt.text(x,y,"%s"%money[x],ha="center",rotation=19)
# three_subplot
x = np.arange(len(grade))
plt.subplot(2,2,3)
plt.title("grade")
plt.bar(x,grade,color="b")
plt.ylim(3,5.5)
plt.xlabel("number")
plt.ylabel("grade")
plt.show()