vgbh
2021-11-20 23:03
import matplotlib.pyplot as plt import matplotlib as mplimport math import numpy as np plt.rcParams['font.sans-serif'] = ['SimHei'] snow_area = [83.1,350.7,5903.3,2716.2,4446.5,2975,4615.1,8543,137.1,5073,980.8,5603.9,829.8,3367.1,7166.3,9521.1,3931.4,4479.5,2077.3,2594.3,289.3,1260.9,4649.5,1816.5,3255,176.2,2548.7,1966.9,159.4,579.9,2297.1] total_output = [52.3,194.2,3321.9,1232.9,2492.3,2017.1,3601.6,5435.2,98.6,3360.6,656,3252.5,496.1,2029.9,4505.2,5777,2428.5,2805.2,1170.8,1420.6,149.2,806.2,2846.6,855.5,1567.7,99.8,1114.2,883.1,61.1,331.8,1474.81] per_hectare = [6296,5538,5627,4539,5605,6780,7804,6362,7190,6624,6689,5804,5978,6028,6287,6068,6177,6262,5636,5476,5157,6394,6122,4710,4816,5663,4371,4490,3832,5721,6420] area = ['北京','天津','河北','山西','内蒙古','辽宁','吉林','黑龙江','上海','江苏','浙江','安徽','福建','江西','山东','河南','湖北','湖南','广东','广西','海南','重庆','四川','贵州','云南','西藏','陕西','甘肃','青海','宁夏','新疆'] print(snow_area, total_output, per_hectare, area) # 最大值 snow_area_max = max(snow_area) total_output_max = max(total_output) per_hectare_max = max(per_hectare) print(snow_area_max, total_output_max, per_hectare_max) # 均值 snow_area_mean = sum(snow_area) / len(snow_area) total_output_mean = sum(total_output) / len(total_output) per_hectare_mean = sum(per_hectare) / len(per_hectare) print(snow_area_mean, total_output_mean, per_hectare_mean) # 中位数 def median(List): List = sorted(List) if (len(List) % 2 == 1): return List[len(List)//2] else: return (List[len(List)//2] + List[len(List)//2-1]) / 2 snow_area_median = median(snow_area) total_output_median = median(total_output) per_hectare_median = median(per_hectare) print(snow_area_median, total_output_median, per_hectare_median) # 标准差 def stdev(List): mean = sum(List) / len(List) Sum = 0 for item in List: Sum += (item - mean) ** 2 Sum /= len(List) return math.sqrt(Sum) snow_area_stdev = stdev(snow_area) total_output_stdev = stdev(total_output) per_hectare_stdev = stdev(per_hectare) print(snow_area_stdev, total_output_stdev, per_hectare_stdev) # 柱状图 plt.figure(figsize=(20, 10)) print(len(snow_area)) plt.bar(range(1, len(snow_area)+1), snow_area) plt.xticks(range(1, len(snow_area)+1), area) # plt.title('各省降雪面积柱状图') plt.show() # 饼图 plt.figure(figsize=(15, 15)) plt.pie(snow_area, labels=area, autopct='%1.2f%%') # plt.title('各省降雪面积占比图') plt.show() # 气泡图 - 反应降雪面积、降雪总量、单位降雪量 plt.figure(figsize=(10, 7)) per_hectare = [item/25 for item in per_hectare] colors = np.random.rand(len(snow_area)) plt.scatter(snow_area, total_output, s=per_hectare, c=colors, alpha=0.5) # plt.xlabel('降雪面积') # plt.ylabel('降雪总量') # plt.title('降雪面积/单位/单位降雪量气泡图') plt.show()
还没有人回答问题,可以看看其他问题
数据可视化利器之Matplotlib
8930 学习 · 13 问题
相似问题