Data visualization (mathematical modeling used in the drawing)

 

01 Histogram

from pylab Import *   # two lines of code, designed to display the man problem 

mpl.rcParams [ ' font.sans serif- ' ] = [ ' the Microsoft YaHei ' ]   # two lines of code, designed to display the man problem 

X1 = NP .arange (2004, 2017 ) 
y1 = [970279, 1259308, 1127571, 1,163,959, 1.16954 million, 1,076,938, 991.35 thousand, 953 275, 951 508, 904 434, 889 381, 864 015, 836 236 ,] 
y1 = np.array (y1)
 # y2 = [1435 , 3402, 3339, 3669, 2802, 3783, 3000, 2840, 2662, 2576, 2240 is, 2280, 2465] 

plt.figure ( . 1 ) 
plt.bar (X1, Y1 / 10000, 0.6, Color = "Coral " ) 
plt.title ( " relationship with the incidence of time " ) 
plt.xlabel (U " Year " ) 
plt.ylabel (U " number of cases " ) 
plt.text ( 2001.5, 127, " Unit: million " )   # in the graph anywhere to add some comments or explanation 
plt.show ()

02 line chart

# "" " 
# @Author: Zhao 
# @ide: PyCharm 
# @createTime: 2019-05-26 
# " "" 
Import numpy AS NP
 from pylab Import *   # two lines of code, designed to show man problem 

plt.rcParams [ ' font.sans serif- ' ] = [ ' the Microsoft YaHei ' ]   # two lines of code, designed to display the man problem 

X1 = np.arange (2004, 2017 ) 
X2 = np.arange (2004, 2020 ) 

Y1 = [970279, 1259308, 1127571, 1163959, 1169540, 1076938, 991350, 953275, 951508, 904434, 889381, 864015, 836236,] 
Y1 = np.array (Y1) 
Y2 = [1,041,613.1, 1144841.3, 1,148,142.4, 1155784.4, 1,163,656.7, 1,120,077.3, 1,049,225.1, 992,511.8, 965,732.8, 931,802.3 ,
       906,496.6, 882,183.2, 856,137.6, 807,201.4, 776,392.1, 743,850.4 ] 
Y2 = np.array (Y2) 
Y3 = [970.28 thousand, 1228788, 1,187,444, 1,146,911, 1,107,177, 1.0682 million, 1,029,999, 992 514, 955.77 thousand, 919 738, 884 407, 849 761, 815 788 ,
       749.8 thousand, 717.8 thousand, 686.36 thousand ] 
Y3 = np.array (Y3) 

plt.figure ( . 1 ) 

plt.plot (X1, Y1 / 10000, label = ' actual number of cases ' , C = ' R & lt ') 
Plt.scatter (X1, Y1 / 10000, C = ' R & lt ' ) 
plt.plot (X2, Y2 / 10000, label = ' Cubic Exponential Smoothing predicted number of cases ' ) 
plt.scatter (X2, Y2 / 10000 ) 
PLT. Plot (X2, Y3 / 10000, label = ' gray model to predict the incidence of persons ' , C = ' G ' ) 
plt.scatter (X2, Y3 / 10000, C = ' G ' ) 
plt.title ( " number of cases and time trends " ) 
plt.xlabel (U " Year " ) 
plt.ylabel (U "Number of cases . ") 
Plt.legend () 
plt.xticks (the Range ( 2004, 2021, 2 )) 
plt.text ( 2001, 127, " Unit: million " ) 

plt.show ()

03 Pie Chart

import pandas as pd
import numpy as np
from collections import Counter
from pylab import *  # 这两行代码,专门用来显示汉子问题

mpl.rcParams['font.sans-serif'] = ['Microsoft YaHei']  # 这两行代码,专门用来显示汉子问题

import heapq


def plot_pie(x, y):
    colors = 'yellowgreen', 'gold', 'lightskyblue', 'lightcoral', 'red', 'orange', 'blue', 'yellow', 'green',
    explode = 0, 0, 0, 0, 0, 0, 0, 0, 0,
    plt.pie(y, explode=explode, labels=x, colors=colors, autopct='%1.1f%%', shadow=False, startangle=50)
    plt.axis('equal')
    plt.show()


if __name__ == '__main__':
    result = [586320., 88228., 50480., 44760., 40888., 32516., 24806., 22952., 47127]

    x = '农民', '家务及待业', '工人', '学生', '离退人员', '其他', '民工', '不详', '其余职业'
    plot_pie(x, result)

04双坐标轴的折线图

import numpy as np
import matplotlib.pyplot as plt
from matplotlib import rc

rc('mathtext', default='regular')
plt.rcParams['font.sans-serif'] = ['Microsoft YaHei']  # 这两行代码,专门用来显示汉子问题
guangDong = [5664.37, 9485.99, 16153.25, 24834.65, 31551.37]
heNan = [5633.24, 9333.4, 15967.61, 24791.83, 32665.38]
siChuan = [1677.8, 2884.11, 4602.16, 8086.86, 11776.73]
guangDong = np.array(guangDong)
heNan = np.array(heNan)
siChuan = np.array(siChuan)
guangDongFB = [42883.0, 66049.0, 56753.0, 59090.0, 51157.0]
heNanFB = [59744.0, 64005.0, 48479.0, 48045.0, 43712.0]
siChuanFB = [46728.0, 63842.0, 49049.0, 46783.0, 46117.0]
guangDongFB = np.array(guangDongFB)
heNanFB = np.array(heNanFB)
siChuanFB = np.array(siChuanFB)
x = np.arange(2004, 2017, 3)

fig = plt.figure()
ax = fig.add_subplot(111)
ax.plot(x, guangDong / 10000, c='red', label='湖南GDP')
ax.plot(x, heNan / 10000, c='blue', label='湖北GDP')
ax.plot(x, siChuan / 10000, c='orange', label='贵州GDP')
ax2 = ax.twinx()
ax2.plot(x, guangDongFB / 10000, '--', c="red", label='湖南发病人数')
ax2.plot(x, heNanFB / 10000, '--', c="blue", label='湖北发病人数')
ax2.plot(x, siChuanFB / 10000, '--', c="orange", label='贵州发病人数')
ax.legend(loc=0)
ax.grid()
ax.set_xlabel("时间")
ax.set_ylabel("GDP")
ax2.set_ylabel("发病人数")
# ax.set_ylim(-20, 100)
ax2.legend(loc=0)
# plt.savefig('0.png')
plt.text(2001.5, 6.65, "单位:万亿元")
plt.text(2016.6, 6.65, "单位:万人")
plt.show()

 

Guess you like

Origin www.cnblogs.com/xinmomoyan/p/10936518.html