首页
/
每日頭條
/
生活
/
python雷達圖導入數據
python雷達圖導入數據
更新时间:2024-09-29 09:18:34

雷達圖是以從同一點開始的軸上表示的三個或更多個定量變量的二維圖表的形式顯示多變量數據的圖形方法,雷達圖通常用于綜合分析多個指标,具有完整,清晰和直觀的優點。

python雷達圖導入數據(python制作雷達圖)1

下面以實際例子給大家講解一下雷達圖的應用場景和繪制方法:

一、比較汽車性能

這類雷達圖一般用于比較同類事物不同緯度性能的優劣,以奧迪A4L時尚動感型和凱迪拉克CT4精英型為例,我們來畫一下這兩種汽車的雷達圖,代碼如下:

importpyecharts.optionsasopts frompyecharts.chartsimportRadar v1=[[110,9.7,6.2,56,150,1610]] v2=[[174,6.9,6.8,66,237,1540]] c=( Radar(init_opts=opts.InitOpts(bg_color="#3CB371"))#設置背景顔色 .add_schema( schema=[ opts.RadarIndicatorItem(name="最大功率率(KW)",max_=200), opts.RadarIndicatorItem(name="百米提速(秒)",max_=12), opts.RadarIndicatorItem(name="綜合油耗(L/100KM)",max_=20), opts.RadarIndicatorItem(name="油箱容積(L)",max_=100), opts.RadarIndicatorItem(name="馬力(Ps)",max_=300), opts.RadarIndicatorItem(name="整車質量KG()",max_=2000), ], splitarea_opt=opts.SplitAreaOpts( is_show=True,areastyle_opts=opts.AreaStyleOpts(opacity=1)#是否顯示分隔區域,透明度設置為1 ), textstyle_opts=opts.TextStyleOpts(color="#fff"), ) .add( series_name="奧迪A4L時尚動感型", data=v1, linestyle_opts=opts.LineStyleOpts(color="#8B008B",width=2),#線的顔色、寬度 ) .add( series_name="凱迪拉克CT4精英型", data=v2, linestyle_opts=opts.LineStyleOpts(color="#FFA500",width=2),#線的顔色、寬度 ) .set_series_opts(label_opts=opts.LabelOpts(is_show=False))#不顯示數字 .set_global_opts( title_opts=opts.TitleOpts(title="汽車性能比較"),legend_opts=opts.LegendOpts() ) ) c.render_notebook()

參數介紹:

1.通過設置InitOpts的bg_color參數,可以改變背景顔色2.通過設置add_schema的schema參數,可以添加更多緯度變量3.通過設置LineStyleOpts的color參數,可以設置線的顔色和寬度

通過雷達圖,可以清晰的比較兩種汽車性能指标的好壞,非常直觀

如果感覺兩台車不過瘾,我們可以再加1台:

python雷達圖導入數據(python制作雷達圖)2

二、比較不同城市近期天氣狀況

frompyechartsimportoptionsasopts frompyecharts.chartsimportRadar value_bj=[ [55,9,56,0.46,18,6,1], [25,11,21,0.65,34,9,2], [56,7,63,0.3,14,5,3], [33,7,29,0.33,16,6,4], [42,24,44,0.76,40,16,5], [82,58,90,1.77,68,33,6], [74,49,77,1.46,48,27,7], [78,55,80,1.29,59,29,8], [267,216,280,4.8,108,64,9], [185,127,216,2.52,61,27,10], [39,19,38,0.57,31,15,11], [41,11,40,0.43,21,7,12], ] value_sh=[ [91,45,125,0.82,34,23,1], [65,27,78,0.86,45,29,2], [83,60,84,1.09,73,27,3], [109,81,121,1.28,68,51,4], [106,77,114,1.07,55,51,5], [109,81,121,1.28,68,51,6], [106,77,114,1.07,55,51,7], [89,65,78,0.86,51,26,8], [53,33,47,0.64,50,17,9], [80,55,80,1.01,75,24,10], [117,81,124,1.03,45,24,11], [99,71,142,1.1,62,42,12], ] c_schema=[ {"name":"AQI","max":300,"min":5}, {"name":"PM2.5","max":250,"min":20}, {"name":"PM10","max":300,"min":5}, {"name":"CO","max":5}, {"name":"NO2","max":200}, {"name":"SO2","max":100}, ] c=( Radar(init_opts=opts.InitOpts(bg_color="#8B658B")) .add_schema(schema=c_schema,shape="polygon") .add("北京",value_bj,color="#8B008B",linestyle_opts=opts.LineStyleOpts(width=2)) .add("上海",value_sh,color="#FF4500",linestyle_opts=opts.LineStyleOpts(width=2)) .set_series_opts(label_opts=opts.LabelOpts(is_show=False)) .set_global_opts(title_opts=opts.TitleOpts(title="一線城市空氣質量比較")) ) c.render_notebook()

通過增加數據種類,可以比較同一緯度、不同時間下的差距,如上圖,通過展示北京、上海兩座城市12天的天氣情況,可以清晰的看出上海的天氣要比北京好。

-完-

完整代碼請關注公衆号【python數據分析之禅】并回複雷達圖獲取

,
Comments
Welcome to tft每日頭條 comments! Please keep conversations courteous and on-topic. To fosterproductive and respectful conversations, you may see comments from our Community Managers.
Sign up to post
Sort by
Show More Comments
Copyright 2023-2024 - www.tftnews.com All Rights Reserved