Python3【pyecharts 0.5.11】pyecharts图表生成总结

首先,下载pyecharts 0.5.11版本

命令安装:pip install pyecharts==0.5.11   (注意是两个等号)

其次,安装生成城市、国家图必备的插件,如下图:

Python3【pyecharts 0.5.11】pyecharts图表生成总结_第1张图片

插件准备完毕,来看实例:

数据监控大图:

Python3【pyecharts 0.5.11】pyecharts图表生成总结_第2张图片

核心代码:

from pyecharts import Page,Bar,Funnel
import os as os
from bs4 import BeautifulSoup

page=Page()
bar=Bar("商品销量","各季度的商品销量",title_pos="center")
bar.use_theme("dark")   #修改图表主题
bar.add("2018Q3",["轴承","弹簧","齿轮","导轨","丝杠"],[25,23,17,14,17],mark_point=["min","max"])  #追加最大值标记点、最小值标记点
bar.add("2018Q4",["轴承","弹簧","齿轮","导轨","丝杠"],[23,21,19,19,13],mark_point=["min","max"],bar_category_gap=45,is_legend_show=False) #追加最大值标记点、最小值标记点、修改柱间隔、是否显示图例
page.add_chart(bar,name="bar")
funnel=Funnel("订单转化效率","今日用户的订单转化效率",title_pos="center")    #修改标题位置
funnel.use_theme("dark")    #修改图表主题
funnel.add("",["访问","搜索","点击","加购","订单"],[100.00,78.12,35.74,17.17,2.62],is_label_show=True,is_legend_show=False,label_pos="outside")   #是否显示标签、是否显示图例、标签位置
funnel._option['series'][0]["top"]=70   #修改上间隔
funnel._option['series'][0]["bottom"]=20    #修改下间隔
funnel._option['series'][0]["left"]="5%"    #修改漏斗图左间隔
funnel._option['series'][0]["width"]="90%"  #修改漏斗图宽度
page.add_chart(funnel,name="funnel")
page.render("page.html")
with open(os.path.join(os.path.abspath("."),"page.html"),'r+',encoding="utf8") as html:
    html_bf=BeautifulSoup(html,"lxml")
    divs=html_bf.find_all("div")
    divs[0]["style"]="width:600px;height:400px;position:absolute;top:70px;left:0px;border-style:solid;border-color:#444444;border-width:3px;"    #修改图表大小、位置、边框
    divs[1]["style"]="width:600px;height:400px;position:absolute;top:70px;left:600px;border-style:solid;border-color:#444444;border-width:3px;"  #修改图表大小、位置、边框
    body=html_bf.find("body")
    body["style"]="background-color:#333333;"
    div_title="
\n基于pyecharts的BI监控大屏
" #修改页面背景色、加标题 body.insert(0,BeautifulSoup(div_title,"lxml").div) html_new=str(html_bf) html.seek(0,0) html.truncate() html.write(html_new)

实例一:生成中国地图

import numpy as np
from pyecharts import Map
areas = ['北京','广西','湖南','江西','福建','山东']
values = np.random.randint(1,100,size = 6)
test_map = Map("中国地图", width=1200, height=600)
test_map.add("", areas, values, maptype='china', is_visualmap=True,
        visual_text_color='#000', is_label_show=True)
test_map.render('ditu.html')  
print('已生成')

Python3【pyecharts 0.5.11】pyecharts图表生成总结_第3张图片

实例二:生成三个季度的统计柱状图

from pyecharts import Bar

bar=Bar("商品销量","各季度的商品销量",title_color ="#c1392b")
bar.add("2018Q2",["轴承","弹簧","齿轮","导轨","丝杠"],[17,23,25,14,17])
bar.add("2018Q3",["轴承","弹簧","齿轮","导轨","丝杠"],[17,23,25,14,17])
bar.add("2018Q4",["轴承","弹簧","齿轮","导轨","丝杠"],[19,21,23,19,13],xaxis_label_textsize=24)

bar.render("bar.html")

Python3【pyecharts 0.5.11】pyecharts图表生成总结_第4张图片

实例三:生成饼图

import random
from pyecharts import Pie
import config as fp
X_AXIS = ["衬衫", "羊毛衫", "雪纺衫", "裤子", "高跟鞋", "袜子"]
bar = Pie("我的第一个图表", "这里是副标题")

# bar.use_theme("roma")
bar.add("商家A", X_AXIS, [random.randint(10, 100) for _ in range(6)])
bar.add("商家B", X_AXIS, [random.randint(10, 100) for _ in range(6)])

bar.render()
bar.render(fp.basedir+'\img\pie.html')   #保存图片的路径

Python3【pyecharts 0.5.11】pyecharts图表生成总结_第5张图片

 

实例四:全国空气质量图示

from pyecharts import Geo
import os

basedir = os.path.abspath(os.path.dirname(__file__))
data = [("北京", 9), ("山东", 12), ("招远", 12), ("舟山", 12), ("齐齐哈尔", 14), ("盐城", 15)]

geo = Geo("全国主要城市空气质量", "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, type="effectScatter", is_random=True, effect_scale=5)

geo.show_config()
geo.render('a.html')

Python3【pyecharts 0.5.11】pyecharts图表生成总结_第6张图片

我只是小白,不要崇拜~

你可能感兴趣的:(Python3,python,数据可视化)