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

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

系統 1809 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條評論
主站蜘蛛池模板: 福建省| 邯郸市| 女性| 星座| 孟州市| 仁寿县| 通辽市| 长泰县| 金华市| 无棣县| 泸水县| 炉霍县| 保康县| 湟源县| 延安市| 印江| 饶河县| 西平县| 海兴县| 九江县| 都昌县| 舞钢市| 二连浩特市| 夹江县| 监利县| 柘荣县| 云安县| 奉贤区| 德兴市| 武城县| 金沙县| 兴海县| 府谷县| 鄂托克旗| 罗江县| 陇南市| 南平市| 车险| 安阳县| 平谷区| 防城港市|