日韩久久久精品,亚洲精品久久久久久久久久久,亚洲欧美一区二区三区国产精品 ,一区二区福利

python---對爬取的湛江天氣信息圖形化

系統 1708 0
            1.讀取文件;
2.獲得想要的數據內容:日期、最低溫、最高溫
3.繪制圖形。 x軸:日期;  y軸:溫度變化。
          
            
              def read_weather_file():
    """讀取文件,提取內容"""
    files = open("./weather/weather.json","r",encoding="utf-8")
    weather_content = files.read()
    # print("天氣信息:",weather_content)
    # print(type(weather_content))
    files.close()
    #把json數據轉換成python類型
    py_datas = json.loads(weather_content)
    # print(py_data)
    # print(type(py_data))
    # 日期
    date_datas = []
    # 最低溫
    tem_down_datas = []
    # 最高溫
    tem_up_datas = []
    # 遍歷
    for element in py_datas:
        # print(element)
        date = element["name"]
        # print(date)
        date_datas.append(date)
        tem_down_datas.append(int(element["tem_low"][:-1]))
        tem_up_datas.append(int(element["tem_up"]))
    # print(date_datas)
    # print(tem_down_datas)
    # print(tem_up_datas)
    # print(type(tem_up_datas))
    return date_datas,tem_up_datas,tem_down_datas
            
          
            
              # 繪圖
    # 顯示中文
    pyplot.rcParams["font.sans-serif"] = ["SimHei"]
    # X軸
    x = [i for i in range(len(datas))]
    print(x)
    # 繪制
    pyplot.plot(x,tem_down,label="最低溫")
    pyplot.plot(x,tem_up,label="最高溫")
    # 限制Y軸的最大最小值
    pyplot.ylim(20,40)
    # Y刻度
    y_tick = [i for i in range(20,40)]
    pyplot.yticks(y_tick)
    # X軸
    pyplot.xticks(x,datas,rotation=45)
    # 圖例
    pyplot.legend(loc="lower left")
    # 網格
    pyplot.grid(alpha=0.4)
    # 標題
    pyplot.title("湛江一周天氣預報最高最低溫情況圖")
    pyplot.ylabel("溫度(單位:℃)")
    pyplot.xlabel("時間日期")

    pyplot.show()
            
          

?

?

python---對爬取的湛江天氣信息圖形化_第1張圖片

?

?


更多文章、技術交流、商務合作、聯系博主

微信掃碼或搜索:z360901061

微信掃一掃加我為好友

QQ號聯系: 360901061

您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點擊下面給點支持吧,站長非常感激您!手機微信長按不能支付解決辦法:請將微信支付二維碼保存到相冊,切換到微信,然后點擊微信右上角掃一掃功能,選擇支付二維碼完成支付。

【本文對您有幫助就好】

您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描上面二維碼支持博主2元、5元、10元、自定義金額等您想捐的金額吧,站長會非常 感謝您的哦!??!

發表我的評論
最新評論 總共0條評論
主站蜘蛛池模板: 阿克苏市| 白朗县| 界首市| 鄱阳县| 江津市| 栾城县| 徐水县| 兰溪市| 阜城县| 霸州市| 洛浦县| 吐鲁番市| 潮安县| 泰安市| 大石桥市| 灵台县| 临澧县| 青海省| 武强县| 茌平县| 岗巴县| 屯留县| 西乌珠穆沁旗| 肇州县| 武穴市| 济源市| 雷州市| 宁陕县| 梓潼县| 丹凤县| 许昌县| 芜湖市| 古交市| 惠来县| 伊金霍洛旗| 宝兴县| 宝应县| 叶城县| 甘泉县| 南通市| 临潭县|