1.安装要注意版本,默认pip install pyecharts安装的是最高版本,导入要使用最新的from pyecharts.charts import Bars
如要指定版本安装需要pip wheel
pip install pyecharts==0.1.9.4
安装完成后pip list--查看已安装库的列表
2.注意在本项目或是其他的文件夹中是否 存在有pyecharts命名的py文件,有执行from pyecharts import Bars 就会报ImportError: cannot import name 'Bar' from 'pyecharts'的错误
一、柱状图
from pyecharts import Bar data=['羊毛衫','高跟鞋','裤子','衬衫','短袖'] v1=[5,24,5,65,4] bar=Bar('我的第一个图表') bar.add('一品楼销售情况',data,v1) # bar.print_echarts_options() # 该行只为了打印配置项,方便调试时使用 #bar.show_config() bar.render(r'C:/Users/xqhu/Desktop/pyechartstest.html')#生成本地html文件
from pyecharts import Bar data=['羊毛衫','高跟鞋','裤子','衬衫','短袖'] v1=[5,24,5,65,4] v2=[16,33,11,0,1] bar=Bar('我的第一个图表') bar.add('商家1',data,v1,is_label_show=True) bar.add('商家2',data,v2,is_label_show=True) bar.render(r'C:/Users/xqhu/Desktop/pyechartstest.html')#生成本地html文件
from pyecharts import Bar data=['羊毛衫','高跟鞋','裤子','衬衫','短袖'] v1=[5,24,5,65,4] v2=[16,33,11,0,1] bar=Bar('我的第一个图表') bar.add('商家1',data,v1,is_convert=True) bar.add('商家2',data,v2,is_convert=True) #bar.add('商家2',data,v2) bar.render(r'C:/Users/xqhu/Desktop/pyechartstest.html')#生成本地html文件
二、饼图
from pyecharts import Pie data=['羊毛衫','高跟鞋','裤子','衬衫','短袖'] v1=[5,24,5,65,4] pie=Pie('各产品销售情况') pie.add('',data,v1,is_label_show=True) pie.render(r'C:/Users/xqhu/Desktop/pyechartstest.html')#生成本地html文件
from pyecharts import Pie data=['羊毛衫','高跟鞋','裤子','衬衫','短袖'] v1=[5,24,5,65,4] pie=Pie('各产品销售情况',title_pos='center') pie.add('',data,v1,label_text_color=None,is_label_show=True legend_pos='left',legend_orient='vertical',radius=[10,60]) #label_text_color指定饼图字体的颜色,is_label_show指定饼图上展示百分比 #legend_pos指定种类图标靠左,legend_orient指定种类图标向下排列 #radius指定空心圆 pie.render(r'C:/Users/xqhu/Desktop/pyechartstest.html')#生成本地html文件
三、散点图
from pyecharts import Scatter v1=[10,20,30,40,50,60] v2=[10,20,30,40,50,60] scatter=Scatter("散点图示例") scatter.add("A",v1,v2) scatter.add("B",v1[::-1],v2) scatter
四、仪表盘
from pyecharts import Gauge gauge=Gauge("业务指标完成率—仪表盘") gauge.add("业务指标","完成率",66.66) gauge
五、热力图
import random from pyecharts import HeatMap x_axis=[ "12a","1a","2a","3a","4a","5a","6a","7a","8a","9a","10a","11a", "12p","1p","2p","3p","4p","5p","6p","7p","8p","9p","10p","11p",] y_axis=[ "Saturday","Friday","Thursday","Wednesday","Tuesday","Monday","Sunday"] data=[[i,j,random.randint(0,50)] for i in range(24) for j in range(7)] heatmap=HeatMap() heatmap.add("热力图直角坐标系",x_axis,y_axis,data,is_visualmap=True, visual_text_color="#000",visual_orient="horizontal") heatmap
六、漏斗图
from pyecharts import Funnel attr=["潜在","接触","意向","明确","投入","谈判","成交"] value=[140,120,100,80,60,40,20] funnel=Funnel("销售管理分析漏斗图") funnel.add("商品",attr,value,is_label_show=True, label_pos="inside",label_text_color="#fff") funnel.render(r'C:/Users/xqhu/Desktop/pyechartstest.html')#生成本地html文件
七、词云图
from pyecharts import WordCloud name=[ "Sam s Club","Macys","Amy Schumer","Jurassic World","Charter Communications", "Chick Fil A","Planet Fitness","Pitch Perfect","Express","Home","Johnny Depp", "Lena Dunham","Lewis Hamilton","KXAN","Mary Ellen Mark","Farrah Abraham", "Rita Ora","Serena Williams","NCAA baseball tournament","Point Break" ] value=[ 10000,6181,4386,4055,2467,2244,1898,1484,1112, 965,847,582,555,550,462,366,360,282,273,265] wordcloud=WordCloud(width=1300,height=620) wordcloud.add("",name,value,word_size_range=[20,100]) wordcloud
八、折线图
from pyecharts import Line line=Line("折线图",width=1200) attr=["周一","周二","周三","周四","周五","周六","周日"] line.add("最高气温",attr,[11,11,15,13,12,13,10], mark_point=["max","min"],mark_line=["average"]) line.add("最低气温",attr,[1,-2,2,5,3,2,0], mark_point=["max","min"],mark_line=["average"], legend_pos="20%") line.render(r'C:/Users/xqhu/Desktop/pyechartstest.html')#生成本地html文件
九、组合图
from pyecharts import Line,Pie,Grid line=Line("折线图",width=1200) attr=["周一","周二","周三","周四","周五","周六","周日"] line.add("最高气温",attr,[11,11,15,13,12,13,10], mark_point=["max","min"],mark_line=["average"]) line.add("最低气温",attr,[1,-2,2,5,3,2,0], mark_point=["max","min"],mark_line=["average"], legend_pos="20%") attr=["衬衫","羊毛衫","雪纺衫","裤子","高跟鞋","袜子"] v1=[11,12,13,10,10,10] pie=Pie("饼图",title_pos="55%") pie.add("",attr,v1,radius=[45,65],center=[65,50], legend_pos="80%",legend_orient="vertical") grid=Grid() grid.add(line,grid_right="55%") grid.add(pie,grid_left="60%") grid.render(r'C:/Users/xqhu/Desktop/pyechartstest.html')#生成本地html文件
十、雷达图
View Code
十一、地理图
from pyecharts import Map districts=['黄埔区','徐汇区','长宁区','静安区','普陀区','虹口区','杨浦区','浦东新区','闵行区','宝山区','嘉定区','金山区','松江区' ,'青浦区','奉贤区','崇明区'] values=[10,2,3,5,19,0,7,37,8,15,34,2,32,27,1,3] geo=Map('确诊人数') geo.add('',districts,values,maptype='上海',visual_range=[min(values),max(values)],label_formatter='{b}') #is_visualmap=True geo.render(r'C:/Users/xqhu/Desktop/pyechartstest.html')#生成本地html文件
'''
Bar(柱状图/条形图)
Bar3D(3D 柱状图)
Boxplot(箱形图)
EffectScatter(带有涟漪特效动画的散点图)
Funnel(漏斗图)
Gauge(仪表盘)
Geo(地理坐标系)
Graph(关系图)
HeatMap(热力图)
Kline(K线图)
Line(折线/面积图)
Line3D(3D 折线图)
Liquid(水球图)
Map(地图)
Parallel(平行坐标系)
Pie(饼图)
Polar(极坐标系)
Radar(雷达图)
Sankey(桑基图)
Scatter(散点图)
Scatter3D(3D 散点图)
ThemeRiver(主题河流图)
WordCloud(词云图)
参考:https://www.cnblogs.com/jyroy/p/9446486.html
'''
#专门说明一下,自从 0.3.2 开始,为了缩减项目本身的体积以及维持 pyecharts 项目的轻量化运行,pyecharts 将不再自带地图 js 文件。如用户需要用到地图图表(Geo、Map),可自行安装对应的地图文件包。
否则在用到这两个包的时候,并能完整的显示地图效果。
安装指令:
第一种:pip install 模块名称(国外源址,比较慢)
第二种:pip install -i https://pypi.tuna.tsinghua.edu.cn/simple/ 模块名称(国内源址,很快)
注意:有空格