这篇文章主要介绍了python的pyecharts绘制各种图表详细(附代码),文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧
环境:pyecharts库,echarts-countries-pypkg,echarts-china-provinces-pypkg,echarts-china-cities-pypkg
数据:2018年4月16号的全国各地最高最低和天气类型的数据――2018-4-16.json(爬虫爬的)
代码:天气数据爬虫代码,图表绘制代码 代码地址:https://github.com/goodloving/pyecharts.git(py文件)
一、公共属性
1、标题栏的属性:一般在实例化(初始化)类型时给与,如bar = Bar(“大标题”,“副标题”,・・・各种属性・・・)
title_color = “颜色”:标题颜色,可以是‘red’或者‘#0000′
title_pos = ‘位置’:标题位置,如‘center’,‘left’・・・
width = 1200:图表的宽
height = 800:图表的高
background_color = “颜色”:图表的背景色
・・・・・
2、标签栏的属性:如bar.add(“标签”,x,values,・・・属性・・・)
‘mark_’类,通个’mark_’显示,如 mark_point[‘max’, ‘min’, ‘average’]:标出最大最小和平均值的点,
mark_point_textcolor,mark_line_symbolsize・・・・・
‘legend_’类,如legend_pos=‘left’:标签的位置
‘is_’类,如is_label_show=True:显示每个点的值,is_datazoom_show=True:实现移动控制x轴的数量
is_convert = True:x,y轴是否调换
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')
3、Geo,Map无法显示底图
pyecharts v0.3.2以后,pyecharts 将不再自带地图 js 文件。如用户需要用到地图图表,可自行安装对应的地图文件包。
地图文件被分成了三个 Python 包,分别为:
全球国家地图: echarts-countries-pypkg (1.9MB)
中国省级地图: echarts-china-provinces-pypkg (730KB)
中国市级地图: echarts-china-cities-pypkg (3.8MB)
(1)pycharm直接在设置里面搜索安装这三个库
(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')
2、散点图――EffectScatter
es = pyecharts.EffectScatter("最低气温动态散点图", "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")
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")
4、仪表盘――Guage
gu = pyecharts.Gauge("仪表盘图") gu.add("指标", "达标", 80) gu.render("Guage-eg.html")
5、地理坐标图――Geo
geo = pyecharts.Geo("最高气温地理坐标系图", '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")
6、关系图――Graph(略)
7、折线/面积图――Line
line = pyecharts.Line("气温变化折线图", '2018-4-16', width=12<b style="color:transparent">来源gao@!dai!ma.com搞$$代^@码!网</b>00, 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')
<p style="text
以上就是python的pyecharts绘制各种图表详细(附代码)的详细内容,更多请关注gaodaima搞代码网其它相关文章!