溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點(diǎn)擊 登錄注冊 即表示同意《億速云用戶服務(wù)條款》

python的pyecharts繪制各種圖表詳細(xì)(附代碼)

發(fā)布時(shí)間:2020-10-12 17:38:15 來源:腳本之家 閱讀:182 作者:goodlovingz 欄目:開發(fā)技術(shù)

環(huán)境:pyecharts庫,echarts-countries-pypkg,echarts-china-provinces-pypkg,echarts-china-cities-pypkg

數(shù)據(jù):2018年4月16號的全國各地最高最低和天氣類型的數(shù)據(jù)——2018-4-16.json(爬蟲爬的)

代碼:天氣數(shù)據(jù)爬蟲代碼,圖表繪制代碼 代碼地址:https://github.com/goodloving/pyecharts.git(py文件)

一、公共屬性

1、標(biāo)題欄的屬性:一般在實(shí)例化(初始化)類型時(shí)給與,如bar = Bar(“大標(biāo)題”,“副標(biāo)題”,···各種屬性···)

title_color = “顏色”:標(biāo)題顏色,可以是‘red'或者‘#0000'

title_pos = ‘位置':標(biāo)題位置,如‘center',‘left'···

width = 1200:圖表的寬

height = 800:圖表的高

background_color = "顏色":圖表的背景色

·····

2、標(biāo)簽欄的屬性:如bar.add(“標(biāo)簽”,x,values,···屬性···)

'mark_'類,通個(gè)'mark_'顯示,如 mark_point['max', 'min', 'average']:標(biāo)出最大最小和平均值的點(diǎn),

mark_point_textcolor,mark_line_symbolsize·····

'legend_'類,如legend_pos=‘left':標(biāo)簽的位置

'is_'類,如is_label_show=True:顯示每個(gè)點(diǎn)的值,is_datazoom_show=True:實(shí)現(xiàn)移動(dòng)控制x軸的數(shù)量

is_convert = True:x,y軸是否調(diào)換

eg:

bar = pyecharts.Bar("全國各地最高氣溫", "2018-4-18", title_color='red', title_pos='right', width=1400, height=700, background_color='#404a59')
bar.add("最高氣溫", cities, highs, mark_point=['max', 'min', 'average'], is_label_show=True, is_datazoom_show=True, legend_pos='left')
bar.render('Bar-High.html')

python的pyecharts繪制各種圖表詳細(xì)(附代碼)

3、Geo,Map無法顯示底圖

pyecharts v0.3.2以后,pyecharts 將不再自帶地圖 js 文件。如用戶需要用到地圖圖表,可自行安裝對應(yīng)的地圖文件包。

地圖文件被分成了三個(gè) Python 包,分別為:
全球國家地圖: echarts-countries-pypkg (1.9MB)
中國省級地圖: echarts-china-provinces-pypkg (730KB)

中國市級地圖: echarts-china-cities-pypkg (3.8MB)

(1)pycharm直接在設(shè)置里面搜索安裝這三個(gè)庫

(2)pip安裝

pip install echarts-countries-pypkg

pip install echarts-china-provinces-pypkg

pip install echarts-china-cities-pypkg

二、各種圖表

1.柱狀圖/條形圖——Bar

bar = pyecharts.Bar("全國各地最高最低氣溫", "2018-4-18", title_pos='right', title_color='blue', width=1400, height=700,background_color='white')
bar.add("最高氣溫", cities, highs, mark_point=['max'], legend_text_color='red', is_datazoom_show=True)
bar.add("最低氣溫", cities, lows, mark_line=['min'], legend_text_color='blue' )


bar.render('Bar-High-Low.html')

python的pyecharts繪制各種圖表詳細(xì)(附代碼)

2、散點(diǎn)圖——EffectScatter

es = pyecharts.EffectScatter("最低氣溫動(dòng)態(tài)散點(diǎn)圖", "2018-4-16", title_pos='right', title_color='blue', width=1400, height=700, background_color='white')
es.add("最低溫度", range(0, len(cities)), lows, legend_pos='center', legend_text_color='blue',symbol_size=10, effect_period=3, effect_scale=3.5, symbol='pin',is_datazoom_show=True,is_label_show=True)


es.render("EffectScatter-low.html")

python的pyecharts繪制各種圖表詳細(xì)(附代碼)

3、漏斗與——Funnel

fl = pyecharts.Funnel("最高氣溫漏斗圖", "2018-40-16", title_pos='left', width=1400, height=700)
fl.add("最低氣溫", cities[:15], lows[:15], is_label_show=True, label_pos='inside', label_text_color='white')


fl.render("Funnel-low.html")

python的pyecharts繪制各種圖表詳細(xì)(附代碼)

4、儀表盤——Guage

gu = pyecharts.Gauge("儀表盤圖")
gu.add("指標(biāo)", "達(dá)標(biāo)", 80)


gu.render("Guage-eg.html")

python的pyecharts繪制各種圖表詳細(xì)(附代碼)

5、地理坐標(biāo)圖——Geo

geo = pyecharts.Geo("最高氣溫地理坐標(biāo)系圖", '2018-4-16', title_color='#fff', title_pos='center', width=1200, height=600, background_color='#404a95')
geo.add("最高氣溫", cities, highs, is_visualmap=True, visual_range=[0, 40], visual_text_color='#fff', symbol_size=5, legend_pos='right',is_geo_effect_show=True)


geo.render("Geo-Low.html")

python的pyecharts繪制各種圖表詳細(xì)(附代碼)

6、關(guān)系圖——Graph(略)

7、折線/面積圖——Line

line = pyecharts.Line("氣溫變化折線圖", '2018-4-16', width=1200, height=600)
line.add("最高氣溫", cities, highs, mark_point=['average'], is_datazoom_show=True)
line.add("最低氣溫", cities, lows, mark_line=['average'], is_smooth=True)


line.render('Line-High-Low.html')

python的pyecharts繪制各種圖表詳細(xì)(附代碼)

line = pyecharts.Line("氣溫變化折線圖", '2018-4-16', width=1200, height=600)
line.add("最高氣溫", cities, highs, mark_point=['average'], is_datazoom_show=True, is_fill=True, line_opacity=0.2, area_opacity=0.4)
line.add("最低氣溫", cities, lows, mark_line=['average'], is_smooth=True, is_fill=True, area_color="#000", area_opacity=0.5)


line.render('Area-High-Low.html')

python的pyecharts繪制各種圖表詳細(xì)(附代碼)

8、水滴球——Liquid

lq = pyecharts.Liquid("水滴球")
lq.add("Liquid", [0.8, 0.5, 0.2], is_liquid_outline_show=False, is_liquid_animation=True)


lq.render("LiQuid.html")

python的pyecharts繪制各種圖表詳細(xì)(附代碼)

9、地圖——Map

a_city = []
for i in cities:
a_city.append(i + '市')
map = pyecharts.Map("湖北最低氣溫", width=1200, height=600)
map.add("最低氣溫", a_city, lows, maptype='湖北', is_visualmap=True, visual_text_color='#000', visual_range= [-15, 20])


map.render("Map-low.html")

python的pyecharts繪制各種圖表詳細(xì)(附代碼)

value = [95.1, 23.2, 43.3, 66.4, 88.5]

attr= ["China", "Canada", "Brazil", "Russia", "United States"]

map = Map("世界地圖示例", width=1200, height=600)

map.add("", attr, value, maptype="world", is_visualmap=True, visual_text_color='#000')

map.render('Map-World.html')

python的pyecharts繪制各種圖表詳細(xì)(附代碼)

10、平行坐標(biāo)圖——Parallel

parallel = pyecharts.Parallel("高低溫度的平行坐標(biāo)系圖", '2018-4-16', width=1200, height=600)
parallel.config(cities[:20])
parallel.add("高低溫", [highs[:20], lows[:20]], is_random=True)


parallel.render('Parallel-High-Low.html')

python的pyecharts繪制各種圖表詳細(xì)(附代碼)

11、餅圖——Pie

sun = 0
cloud = 0
lit_rain = 0
mit_rain = 0
sail = 0
shadom = 0
z_rain = 0
th_rain = 0
for i in types:
if i == '晴':
sun += 1
elif i == '多云':
cloud += 1
elif i == '小雨':
lit_rain += 1
elif i == '中雨':
mit_rain += 1
elif i == '陰':
shadom += 1
elif i == '陣雨':
z_rain += 1
elif i == '雷陣雨':
th_rain += 1
elif i == '揚(yáng)沙':
sail += 1
pie = pyecharts.Pie("全國天氣類型比例", '2018-4-16')
pie.add('天氣類型', weather, [mit_rain, lit_rain, sail, sun, th_rain, cloud, shadom, z_rain], is_label_show=True)


pie.render('Pie-weather.html')

python的pyecharts繪制各種圖表詳細(xì)(附代碼)

修改:

pie = pyecharts.Pie("全國天氣類型比例", '2018-4-16', title_pos='center')
pie.add('天氣類型', weather, [mit_rain, lit_rain, sail, sun, th_rain, cloud, shadom, z_rain], is_label_show=True, legend_pos='left', label_text_color=None, legend_orient='vertical', radius=[30, 75])


pie.render('Pie-weather.html')

python的pyecharts繪制各種圖表詳細(xì)(附代碼)

pie鑲嵌:

center -> list

餅圖的中心(圓心)坐標(biāo),數(shù)組的第一項(xiàng)是橫坐標(biāo),第二項(xiàng)是縱坐標(biāo),默認(rèn)為 [50, 50]默認(rèn)設(shè)置成百分比,設(shè)置成百分比時(shí)第一項(xiàng)是相對于容器寬度,第二項(xiàng)是相對于容器高度

rosetype -> str

是否展示成南丁格爾圖,通過半徑區(qū)分?jǐn)?shù)據(jù)大小,有'radius'和'area'兩種模式。默認(rèn)為'radius'radius:扇區(qū)圓心角展現(xiàn)數(shù)據(jù)的百分比,半徑展現(xiàn)數(shù)據(jù)的大小area:所有扇區(qū)圓心角相同,僅通過半徑展現(xiàn)數(shù)據(jù)大小

pie = pyecharts.Pie("全國天氣類型比例", '2018-4-16')
pie.add('', weather, [mit_rain, lit_rain, sail, sun, th_rain, cloud, shadom, z_rain], is_label_show=True, label_text_color=None, legend_orient='vertical', radius=[40, 50], center=[50, 50])
pie.add('', ['中雨', '小雨', '揚(yáng)沙', '晴'], [lit_rain, mit_rain, sun, sail], radius=[10, 35], center=[50, 50], rosetype='area')


pie.render('Pie-weather.html')

python的pyecharts繪制各種圖表詳細(xì)(附代碼)

至此,pyecharts的大多數(shù)圖標(biāo)的繪制我們都可以實(shí)現(xiàn)了,更多知識(shí)可以查看下面鏈接

以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持億速云。

向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI