Python大作业进阶(四)

绘制动态图——根据时间

数据来源:数据来源
没有数据整合,只为演示绘图(好吧其实是我爬虫的时候出现了些小问题)

import matplotlib.pyplot as plt
import csv
list_1 = [679.09,824.39,859.82,911.58,1030.73,1071.45,1312.34,1447.51,1470.1,1232.34,1162.16,1248.27,1469.89,1734.04,1888.72,1794.23,1744.13,1962.22,2279.72,2456.88,
        2552.36,2756.23,2827.69,3039.48,2988.58,3250,3678.7,4100.45,4587.58,4935.83,5373.35,6020.92,7278.5,9098.95,10376.15,12174.59,15180.39,17179.74,18872.87,
        22005.63,27194.53,35673.23,48637.45,61339.89,71813.63,79715.04,85195.51,90564.38,100280.14,110863.12,121717.42,137422.03,161840.16,187318.9,219438.47,270092.32,
        319244.61,348517.74,412119.26,487940.18,538579.95,592963.23,641280.57,685992.95,740060.8,820754.28,900309.48]

list_2 = [0,15.54,4.26,6.87,14.94,5.03,21.2,8.81,-0.35,-27.28,-5.57,10.23,18.21,17.04,10.75,-5.67,-4.06,16.88,19.37,7.01,3.81,7.81,2.33,
        8.69,-1.59,7.6,11.7,7.6,7.8,5.1,9,10.8,15.2,13.4,8.9,11.7,11.2,4.2,3.9,9.3,14.2,13.9,13,11,9.2,9.2,7.8,7.7,8.5,8.3,9.1,10,10.1,
        11.4,12.7,14.2,9.7,9.4,10.6,9.5,7.9,7.8,7.3,6.9,6.7,6.9,6.6]

list_3 = [119.37,141.8,144.43,149.77,165.86,168.1,200.9,217.34,220.38,186.62,174.56,182.94,210.48,242.46,256.83,237.79,225.19,246.5,278.59,
        292.1,296.09,312.52,314.07,331.68,321.12,344.48,384.74,423.16,467.53,496.62,532.74,588.38,702,865.71,972.65,1123.08,1377.99,1535.76,1662.54,
          1912.24,2334.35,3027.16,4080.89,5091.06,5895.21,6480.5,6859.9,7229.33,7942.07,8716.68,9506.2,10666.1,12486.94,14368.03,16738,20494.38,
        24100.21,26179.54,30807.93,36301.56,39874.28,43684.39,47005.4,50027.93,53679.52,59200.61,64643.5]

list_4 = [0,13.06,1.82,4.53,12.57,2.4,18.27,6.72,-0.51,-26.54,-6.34,7.55,15.49,14.29,7.7,-8.06,-6.53,13.72,16.12,4.11,1.29,5.38,0.24,6.78,
        -3.1,6.14,10.2,6.2,6.5,3.8,7.4,9.2,13.7,11.9,7.3,9.9,9.4,2.6,2.4,7.8,12.8,12.6,11.8,9.8,8.8,8.1,6.8,6.7,7.6,7.6,8.4,9.4,9.5,10.7,
        12.1,13.6,9.1,8.9,10.1,9,7.3,7.2,6.8,6.4,6.1,6.3,6.3]

#plt.rcParams['savefig.dpi'] = 200 #图片像素
plt.rcParams['figure.dpi'] = 200 #分辨率
plt.rcParams['figure.figsize'] = (10, 10)        # 图像显示大小
plt.rcParams['font.sans-serif']=['SimHei']   #防止中文标签乱码,还有通过导入字体文件的方法
plt.rcParams['axes.unicode_minus'] = False
plt.rcParams['lines.linewidth'] = 0.7   #设置曲线线条宽度

y1 = []
y2 = []
y3 = []
y4 = []
x = []
num = 1952
ax1 = plt.subplot(221)
ax2 = plt.subplot(222)
ax3 = plt.subplot(223)
ax4 = plt.subplot(224)
plt.suptitle('1952-2018年全国GDP及人均GDP')
for i in range(len(list_1)):
    x.append(num)
    y1.append(list_1[i])  # 每迭代一次,将i放入y1中画出来
    ax1.cla()   # 清除键
    ax1.plot(x,y1, label='全国GDP')
    ax1.legend(loc=1)
    plt.pause(0.1)

    y2.append(list_2[i])  # 每迭代一次,将i放入y1中画出来
    ax2.cla()   # 清除键
    ax2.plot(x,y2, label='全国GDP年增速')
    ax2.legend(loc=1)
    plt.pause(0.1)

    y3.append(list_3[i])  # 每迭代一次,将i放入y1中画出来
    ax3.cla()  # 清除键
    ax3.plot(x,y3, label='人均GDP')
    ax3.legend(loc=1)
    plt.pause(0.1)

    y4.append(list_4[i])  # 每迭代一次,将i放入y1中画出来
    ax4.cla()  # 清除键
    ax4.plot(x,y4, label='人均GDP年增速')
    ax4.legend(loc=1)
    plt.pause(0.1)
    num+=1


(这其实是一个动态图~)
数据的话之后再爬吧

全部评论

相关推荐

10-21 23:48
蚌埠坦克学院
csgq:可能没hc了 昨天一面完秒挂
点赞 评论 收藏
分享
评论
点赞
收藏
分享
牛客网
牛客企业服务