import pyecharts.options as opts
from pyecharts import options as opts
from pyecharts.charts import Line, Pie, Tab
line_x = ['7/14','7/15','7/16','7/17']
line_y1 = [35,34,37,33]
line_y2 = [25,23,28,26]
line_y3 = [30,29,31,27]
line_y4 = [21,20,23,20]
#定义lines_charts函数
def lines_charts(a,b):
c = Line()
c.add_xaxis(xaxis_data= line_x)
c.add_yaxis(series_name="最高温度",y_axis=a)
c.add_yaxis(series_name="最低温度",y_axis=b)
data_zoom = {
"show": False,
"title":{"zoom":'data zoom','back':'data zoom restore'}
}#设置右上角工具显示内容参数
#全局数据项设置,只能设置一次
c.set_global_opts(
title_opts=opts.TitleOpts(title="气温情况"),
legend_opts=opts.LegendOpts(is_show= True), #默认展示图例
tooltip_opts=opts.TooltipOpts(trigger ='axis',axis_pointer_type = 'cross'),#2个数据同时出现,并出现横竖坐标数据
toolbox_opts = opts.ToolboxOpts(is_show = True,orient = 'verticel',#显示功能小图标
feature = opts.ToolBoxFeatureOpts(data_zoom = data_zoom)#不显示data zoom和data zoom restore
)
)
#c.set_global_opts(toolbox_opts = opts.ToolboxOpts(is_show = True))
return c
#绘制图表
c1 = lines_charts(line_y1,line_y2)
c2 = lines_charts(line_y3,line_y4)
c3 = lines_charts(line_y1,line_y4)
tab = Tab()
tab.add(lines_charts(line_y1,line_y2), "重庆")
tab.add(lines_charts(line_y3,line_y4), "贵州")
tab.add(lines_charts(line_y1,line_y4), "云南")
# tab.render("Tab选项卡多图.html")
# tab.render_notebook()
x = ['春季','夏季','冬季','小件']
y = [500,200,50,150]
data_pair = [list(z) for z in list(zip(x,y))]#饼状图只支持[[1,2],[3,4]]类型的数据。zip后的格式为[(1,2),(3,4)],需要转换
def pie_charts():
c = Pie(init_opts=opts.InitOpts(width = "500px",height = "500px"))#设置图片大小
c.add(series_name="适销季节",data_pair = data_pair,label_opts=opts.LabelOpts(is_show = True))#导入数据,设置图片大小
c.set_global_opts(title_opts=opts.TitleOpts(title = "年后季节占比",pos_top = 5 ,pos_left = "center"),
legend_opts = opts.LegendOpts(pos_top='8%',pos_left='30%'))
c.set_series_opts(tooltip_opts = opts.TooltipOpts(trigger = 'item',formatter = "{a} <br/> {b}:{c} ({d}%)"))#同时显示百分比
return c
c = pie_charts()
page = Page(layout=Page.DraggablePageLayout)
page.add(c,tab)
page.render("7.16.html")
报错原因:AttributeError: 'Tab' object has no attribute 'chart_id'
怀疑 是 tensorflow(=1.12.0,python 3.6.5)版本太低
在Anaconda 中 创建一个 虚拟 环境 tf2.0,在tf2.0 中安装 python 3.7 和tensorflow 2.0.0