一锅尘、基本圖形
1.簡單柱狀圖
from pyecharts import Bar,
page = Page()# 生成頁面
attr = ["襯衫","羊毛衫","雪紡衫","褲子","高跟鞋","襪子"]
v1 = [5,20,36,10,75,90]
v2 = [10,25,8,60,20,80]
bar = Bar("柱狀圖數(shù)據(jù)堆疊示例")
bar.add("商家A", attr, v1,is_stack=True)
bar.add("商家B", attr, v2,is_stack=True)
page.add(bar)# step 2
page.render(r'C:\Users\mei-huang\Desktop\render.html')# 指定文件保存位置
2.條形圖
from pyecharts import Bar, Scatter3D,Page
page = Page()# st
attr = ["襯衫","羊毛衫","雪紡衫","褲子","高跟鞋","襪子"]
v1 = [5,20,36,10,75,90]
v2 = [10,25,8,60,20,80]
bar = Bar("柱狀圖數(shù)據(jù)堆疊示例")
bar.add("商家A", attr, v1,is_stack=True,mark_point=['average'])
bar.add("商家B", attr, v2,is_stack=True,is_convert=True) #對圖表進行轉(zhuǎn)置
page.add(bar)# step 2
page.render()# step 3
![水平柱狀圖示例.png](https://upload-images.jianshu.io/upload_images/5063233-ee60761cae02d9ef.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
3.3D散點圖
from pyecharts import Scatter3D,Page
import random
page = Page()# st
data = [[random.randint(0, 100), random.randint(0, 100), random.randint(0, 100)] for _ in range(80)]
range_color = ['#313695', '#4575b4', '#74add1', '#abd9e9', '#e0f3f8', '#ffffbf',
'#fee090', '#fdae61', '#f46d43', '#d73027', '#a50026']
scatter3D = Scatter3D("3D 散點圖示例", width=1200, height=600) #設(shè)置圖表的高和寬
scatter3D.add("", data, is_visualmap=True, visual_range_color=range_color) #視覺映射和顏色選擇
page.add(scatter3D)
page.render()#
散點圖.png
4.數(shù)據(jù)地圖1
from pyecharts import Geo
data = [
("海門", 9),("鄂爾多斯", 12),("招遠", 12),("舟山", 12),("齊齊哈爾", 14),("鹽城", 15),
("赤峰", 16),("青島", 18),("乳山", 18),("金昌", 19),("泉州", 21),("萊西", 21),
("日照", 21),("膠南", 22),("南通", 23),("拉薩", 24),("云浮", 24),("梅州", 25)]
geo = Geo("全國主要城市空氣質(zhì)量", "data from pm2.5", title_color="#fff", title_pos="center",
width=1200, height=600, background_color='#404a59')
attr, value = geo.cast(data)
geo.add("", attr, value, visual_range=[0, 200], visual_text_color="#fff", symbol_size=15, is_visualmap=True)
geo.show_config()
geo.render()
數(shù)據(jù)地圖1.png
5.數(shù)據(jù)地圖2
from pyecharts import Map
districts = ['運河區(qū)', '新華區(qū)', '泊頭市', '任丘市', '黃驊市', '河間市', '滄縣', '青縣', '東光縣', '海興縣', '鹽山縣', '肅寧縣', '南皮縣', '吳橋縣', '獻縣', '孟村回族自治縣']
areas = [109.92, 109.47, 1006.5, 1023.0, 1544.7, 1333.0, 1104.0, 968.0, 730.0, 915.1, 796.0, 525.0, 794.0, 600.0, 1191.0, 387.0]
map_1 = Map("滄州市圖例-各區(qū)面積", width=1200, height=600)
map_1.add("", districts, areas, maptype='滄州', is_visualmap=True, visual_range=[min(areas), max(areas)],
visual_text_color='#000', is_map_symbol_show=False, is_label_show=True)
map_1.render()
數(shù)據(jù)地圖2.png
6.餅圖
from pyecharts import Pie
attr=["襯衫","羊毛衫","雪紡衫","褲子","帽子"]
v1=[10,20,30,40,50]
pie=Pie("產(chǎn)品銷售")
pie.add("z",attr,v1,is_label_show=True)
pie.render()
餅圖.png
7.環(huán)形圖
from pyecharts import Pie
attr=["襯衫","羊毛衫","雪紡衫","褲子","帽子"]
v1=[10,20,30,40,50]
pie=Pie("產(chǎn)品銷售-環(huán)形圖",title_pos='center')
pie.add("z",attr,v1,is_label_show=True,radius=[30,60],label_text_color=None,\
legend_orient='vertical',legend_pos='right')
pie.render()
環(huán)形圖.png
8.散點圖
from pyecharts import Scatter
v1=list(range(1,5,1))
v2=list(range(1,5,1))
scatter=Scatter("散點圖示例")
scatter.add("A",v1,v2)
scatter.add("B",v1[::-1],v2)
scatter.render()
散點圖.png
9.儀表盤
from pyecharts import Gauge
gauge=Gauge("指標完成率")
gauge.add("業(yè)務(wù)指標","完成率",95)
gauge.render()
儀表盤.png
10.漏斗圖
from pyecharts import Funnel
attr=["瀏覽","點擊","下載","安裝","注冊"]
values=[300,200,150,100,80]
funnel=Funnel("用戶轉(zhuǎn)化圖",title_pos="center") #定義和設(shè)置標題
funnel.add("用戶",attr,values,is_label_show=True,label_pos="inside",label_text_color="#fff",legend_pos="top")
funnel.render()
漏斗圖.png
11.折線圖
from pyecharts import Line
line=Line("折線圖")
attr=['7-1','7-2','7-3','7-4','7-5']
line.add("最高在線",attr,[725,284,613,852,679],mark_point=["max","min"],mark_line=["average"])
line.add("平均在線",attr,[30,20,40,80,70],legend_pos="20%")
line.render()
折線圖.png
12.關(guān)系圖
from pyecharts import Graph
nodes =[{"name": "結(jié)點1", "symbolSize": 10}, {"name": "結(jié)點2", "symbolSize": 20}, {"name": "結(jié)點3", "symbolSize": 30}, {"name": "結(jié)點4", "symbolSize": 40}, {"name": "結(jié)點5", "symbolSize": 50}, {"name": "結(jié)點6", "symbolSize": 40}, {"name": "結(jié)點7", "symbolSize": 30}, {"name": "結(jié)點8", "symbolSize": 20}]
links =[]
for i in nodes:
for j in nodes:
links.append({"source": i.get('name'), "target": j.get('name')})
graph =Graph("關(guān)系圖-環(huán)形布局示例")
graph.add("", nodes, links, is_label_show=True, repulsion=80000, layout='circular', label_text_color=None)
graph.show_config()
graph.render()
關(guān)系圖.png
13.折線面積圖
from pyecharts import Line
attr =["襯衫", "羊毛衫", "雪紡衫", "褲子", "高跟鞋", "襪子"]
v1 =[5, 20, 36, 10, 10, 100]
v2 =[55, 60, 16, 20, 15, 80]
line =Line("折線圖-面積圖示例")
line.add("商家A", attr, v1, is_fill=True, line_opacity=0.2, area_opacity=0.4, symbol=None)
line.add("商家B", attr, v2, is_fill=True, area_color='#000', area_opacity=0.3, is_smooth=True)
#line.show_config()
line.render()
折線面積圖.png
14.玫瑰餅圖
from pyecharts import Pie
attr =["襯衫", "羊毛衫", "雪紡衫", "褲子", "高跟鞋", "襪子"]
v1 =[11, 12, 13, 10, 10, 10]
v2 =[19, 21, 32, 20, 20, 33]
pie =Pie("餅圖-玫瑰圖示例", title_pos='center', width=900)
pie.add("商品A", attr, v1, center=[25, 50], is_random=True, radius=[30, 75], rosetype='radius')
pie.add("商品B", attr, v2, center=[75, 50], is_random=True, radius=[30, 75], rosetype='area', is_legend_show=False, is_label_show=True)
pie.render()
image.png
15.南丁格爾玫瑰圖
from pyecharts import Polar
radius =['周一', '周二', '周三', '周四', '周五', '周六', '周日']
polar =Polar("極坐標系-堆疊柱狀圖示例", width=1200, height=600)
polar.add("a", [1, 2, 3, 4, 3, 5, 1], radius_data=radius, type='barAngle', is_stack=True)
polar.add("b", [2, 4, 6, 1, 2, 3, 1], radius_data=radius, type='barAngle', is_stack=True)
polar.add("c", [1, 2, 3, 4, 1, 2, 5], radius_data=radius, type='barAngle', is_stack=True)
polar.show_config()
polar.render()
玫瑰圖.png
16.雷達圖
from pyecharts import Radar
schema = [("銷售", 6500), ("管理", 16000), ("信息技術(shù)", 30000), ("客服", 38000), ("研發(fā)", 52000), ("市場", 25000)]
v1 = [[4300, 10000, 28000, 35000, 50000, 19000]]
v2 = [[5000, 14000, 28000, 31000, 42000, 21000]]
radar = Radar()
radar.config(schema)
radar.add("預(yù)算分配", v1, is_splitline=True, is_axisline_show=True)
radar.add("實際開銷", v2, label_color=["#4e79a7"], is_area_show=False)
radar.show_config()
radar.render()
雷達圖.png
17.其他好玩的圖形
import math
from pyecharts import Polar
data =[]
for i in range(361):
t =i /180*math.pi
r =math.sin(2*t) *math.cos(2*t)
data.append([r, i])
polar = Polar("極坐標系示例", width=1200, height=600)
polar.add("Color-Flower", data, start_angle=0, symbol=None, axis_range=[0, None], area_color="#f71f24", area_opacity=0.6)
polar.show_config()
polar.render()
極坐標.png
18.詞云
from pyecharts import WordCloud
name = [
'Though','the answer','this question',
'may at first','seem to border','on the',
'absurd','reflection','will show','that there',
'is a','good deal','more in','it than meets','the eye'
]
value = [10000,6189,4556,2356,2233,
1895,1456,1255,981,875,
542,462,361,265,125]
worldcloud = WordCloud(width = 1300,height = 620)
worldcloud.add('',name,value,word_size_range = [20,100])
worldcloud.render()
詞云.png
19.1赏梗基圖 (1)
from pyecharts import Sankey
nodes = [
{'name': 'category1'}, {'name': 'category2'}, {'name': 'category3'},
{'name': 'category4'}, {'name': 'category5'}, {'name': 'category6'},
]
links = [
{'source': 'category1', 'target': 'category2', 'value': 10},
{'source': 'category2', 'target': 'category3', 'value': 15},
{'source': 'category3', 'target': 'category4', 'value': 20},
{'source': 'category5', 'target': 'category6', 'value': 25}
]
sankey = Sankey("桑基圖示例", width=1200, height=600)
sankey.add("sankey", nodes, links,
line_opacity=0.4, #不透明度哎媚,顏色的深淺
line_curve=0.9, #曲線的扭曲程度
line_color='source',
is_label_show=True, label_pos='right') #是否顯示標簽租漂,標簽的位置
sankey.render()
19.2山着基圖2
桑基圖.png
from pyecharts import Sankey
nodes =[
{"name":"Andriod3"},
{"name":"服務(wù)頻道2"},
{"name":"其它2"},
{"name":"服務(wù)頻道4"},
{"name":"服務(wù)頻道3"},
{"name":"乙方2"},
{"name":"乙方3"},
{"name":"其它3"},
{"name":"Andriod4"},
{"name":"Andriod2"},
{"name":"其它4"},
{"name":"Andriod1"},
{"name":"乙方4"},
{"name":"乙方5"},
{"name":"Andriod5"},
{"name":"服務(wù)頻道5"},
{"name":"其它5"},
]
links = [
{"source":"Andriod1","target":"Andriod2","value":"65"},
{"source":"乙方3","target":"Andriod4","value":"1"},
{"source":"乙方2","target":"Andriod3","value":"1"},
{"source":"服務(wù)頻道3","target":"Andriod4","value":"2"},
{"source":"Andriod2","target":"Andriod3","value":"48"},
{"source":"服務(wù)頻道2","target":"其它3","value":"1"},
{"source":"乙方2","target":"服務(wù)頻道3","value":"1"},
{"source":"Andriod3","target":"Andriod4","value":"35"},
{"source":"Andriod2","target":"服務(wù)頻道3","value":"3"},
{"source":"Andriod4","target":"服務(wù)頻道5","value":"3"},
{"source":"Andriod3","target":"乙方4","value":"1"},
{"source":"Andriod1","target":"服務(wù)頻道2","value":"6"},
{"source":"服務(wù)頻道2","target":"服務(wù)頻道3","value":"2"},
{"source":"其它2","target":"Andriod3","value":"1"},
{"source":"服務(wù)頻道4","target":"Andriod5","value":"1"},
{"source":"Andriod2","target":"乙方3","value":"1"},
{"source":"Andriod1","target":"乙方2","value":"2"},
{"source":"服務(wù)頻道2","target":"Andriod3","value":"1"},
{"source":"Andriod1","target":"其它2","value":"1"},
{"source":"乙方4","target":"Andriod5","value":"1"},
{"source":"服務(wù)頻道3","target":"服務(wù)頻道4","value":"3"},
{"source":"Andriod4","target":"Andriod5","value":"26"},
]
sankey = Sankey("闪ㄖ危基圖示例", width=1200, height=600)
sankey.add("sankey", nodes, links,
line_opacity=0.4, #不透明度秃踩,顏色的深淺
line_curve=0.9, #曲線的扭曲程度
line_color='source',
is_label_show=True, label_pos='right') #是否顯示標簽,標簽的位置
sankey.render()
梢捣ぃ基圖2.png
二憔杨、基本的類
1.Overlap.add()類,組合圖形
add(chart,
xaxis_index = 0,
yaxis_index = 0,
is_add_xaxis = False,
is_add_yaxis = False)
屬性:
is_add_xaxis / is_add_yaxis 是否新增坐標X/Y 默認 False
from pyecharts import Bar,Line,Overlap
attr = ['A','B','C','D','E','F']
v1 = [10,20,30,40,50,60]
v2 = [38,28,35,58,65,100]
bar = Bar('Line - Bar示例')
bar.add('bar',attr,v1)
line = Line()
line.add('line',attr,v2)
overlop = Overlap()
overlop.add(bar,yaxis_index = 10)
overlop.add(line,is_add_yaxis=False) #是否增加新y軸
overlop.render()
重疊組合圖.png
2.Grid()類圖形左右組合
from pyecharts import Bar,Line,Grid
attr = ['A','B','C','D','E','F']
v1 = [10,20,30,40,50,60]
v2 = [38,28,35,58,65,100]
bar = Bar('Line - Bar示例')
bar.add('bar',attr,v1)
line = Line()
line.add('line',attr,v2)
grid = Grid()
grid.add(bar,grid_right="50%")
grid.add(line,grid_left="60%") #是否增加新y軸
grid.render()
Grid左右組合.png
3.Page()類在網(wǎng)頁上豎直排列
#生成數(shù)據(jù)點圖
from pyecharts import Bar,Line,Page
attr = ['A','B','C','D','E','F']
v1 = [10,20,30,40,50,60]
v2 = [38,28,35,58,65,100]
bar = Bar('Line - Bar示例')
bar.add('bar',attr,v1)
line = Line()
line.add('line',attr,v2)
page = Page()
page.add(bar)
page.add(line) #是否增加新y軸
page.render()
page類豎直排列.png
- Timeline() 在時間維度上播放圖形
from pyecharts import Bar, Timeline
from random import randint
attr = ["襯衫", "羊毛衫", "雪紡衫", "褲子", "高跟鞋", "襪子"]
bar_1 = Bar("2012 年銷量", "數(shù)據(jù)純屬虛構(gòu)")
bar_1.add("春季", attr, [randint(10, 100) for _ in range(6)])
bar_1.add("夏季", attr, [randint(10, 100) for _ in range(6)])
bar_1.add("秋季", attr, [randint(10, 100) for _ in range(6)])
bar_1.add("冬季", attr, [randint(10, 100) for _ in range(6)])
bar_2 = Bar("2013 年銷量", "數(shù)據(jù)純屬虛構(gòu)")
bar_2.add("春季", attr, [randint(10, 100) for _ in range(6)])
bar_2.add("夏季", attr, [randint(10, 100) for _ in range(6)])
bar_2.add("秋季", attr, [randint(10, 100) for _ in range(6)])
bar_2.add("冬季", attr, [randint(10, 100) for _ in range(6)])
bar_3 = Bar("2014 年銷量", "數(shù)據(jù)純屬虛構(gòu)")
bar_3.add("春季", attr, [randint(10, 100) for _ in range(6)])
bar_3.add("夏季", attr, [randint(10, 100) for _ in range(6)])
bar_3.add("秋季", attr, [randint(10, 100) for _ in range(6)])
bar_3.add("冬季", attr, [randint(10, 100) for _ in range(6)])
bar_4 = Bar("2015 年銷量", "數(shù)據(jù)純屬虛構(gòu)")
bar_4.add("春季", attr, [randint(10, 100) for _ in range(6)])
bar_4.add("夏季", attr, [randint(10, 100) for _ in range(6)])
bar_4.add("秋季", attr, [randint(10, 100) for _ in range(6)])
bar_4.add("冬季", attr, [randint(10, 100) for _ in range(6)])
bar_5 = Bar("2016 年銷量", "數(shù)據(jù)純屬虛構(gòu)")
bar_5.add("春季", attr, [randint(10, 100) for _ in range(6)])
bar_5.add("夏季", attr, [randint(10, 100) for _ in range(6)])
bar_5.add("秋季", attr, [randint(10, 100) for _ in range(6)])
bar_5.add("冬季", attr, [randint(10, 100) for _ in range(6)], is_legend_show=True)
timeline = Timeline(width=800,height=600
,is_auto_play=True #是否自動播放
,is_loop_play= True #是否循環(huán)播放
,is_timeline_show=True #是否現(xiàn)實時間組件
,is_rewind_play=False #是否方向播放
,timeline_play_interval=1000 #跳動的時間間隔
,timeline_bottom=0) #是否循環(huán)播放
timeline.add(bar_1, '2012 年')
timeline.add(bar_2, '2013 年')
timeline.add(bar_3, '2014 年')
timeline.add(bar_4, '2015 年')
timeline.add(bar_5, '2016 年')
timeline.render()
在時間維度.png