效果是这个样子,就是一个交互的图表集成展示
先把你自己画的所有图片添到里page() ,Page记得要导入一下和Bar,Pie那些pyecharts.charts类里。(画图的代码就省略了太多了,我这里就是举个例子)。把我add的这些图换成你自己。
page = (Page().add(pie1).add(pie2).add(pie3).add(pie4).add(pie5).add(pie6)
.add(pie7).add(pie8).add(pie9).add(pie10).add(pie11).add(pie12).add(pie13).add(pie14).add(pie15)
.add(line1).add(bar1).add(bar2)
)
page.render('用户流失因素EDA.html')
然后
from bs4 import BeautifulSoup
with open("用户流失因素EDA.html", "r+", encoding='utf-8') as html:
html_bf = BeautifulSoup(html, 'lxml')
divs = html_bf.select('.chart-container')
divs[0]["style"] = "width:500px;height:250px;position:absolute;top:50px;left:0px;border-style:solid;border-color:#444444;border-width:3px;"
divs[1]['style'] = "width:500px;height:250px;position:absolute;top:50px;left:500px;border-style:solid;border-color:#444444;border-width:3px;"
divs[2]["style"] = "width:500px;height:250px;position:absolute;top:50px;left:1000px;border-style:solid;border-color:#444444;border-width:3px;"
divs[3]["style"] = "width:500px;height:250px;position:absolute;top:300px;left:0px;border-style:solid;border-color:#444444;border-width:3px;"
divs[4]["style"] = "width:500px;height:250px;position:absolute;top:300px;left:500px;border-style:solid;border-color:#444444;border-width:3px;"
divs[13]["style"] = "width:500px;height:250px;position:absolute;top:300px;left:1000px;border-style:solid;border-color:#444444;border-width:3px;"
divs[5]["style"] = "width:750px;height:200px;position:absolute;top:550px;left:0px;border-style:solid;border-color:#444444;border-width:3px;"
divs[6]["style"] = "width:750px;height:200px;position:absolute;top:550px;left:750px;border-style:solid;border-color:#444444;border-width:3px;"
divs[7]["style"] = "width:750px;height:200px;position:absolute;top:750px;left:0px;border-style:solid;border-color:#444444;border-width:3px;"
divs[8]["style"] = "width:750px;height:200px;position:absolute;top:750px;left:750px;border-style:solid;border-color:#444444;border-width:3px;"
divs[9]["style"] = "width:750px;height:200px;position:absolute;top:950px;left:0px;border-style:solid;border-color:#444444;border-width:3px;"
divs[10]["style"] = "width:750px;height:200px;position:absolute;top:950px;left:750px;border-style:solid;border-color:#444444;border-width:3px;"
divs[11]["style"] = "width:750px;height:200px;position:absolute;top:1150px;left:0px;border-style:solid;border-color:#444444;border-width:3px;"
divs[12]["style"] = "width:750px;height:200px;position:absolute;top:1150px;left:750px;border-style:solid;border-color:#444444;border-width:3px;"
divs[14]["style"] = "width:600px;height:600px;position:absolute;top:1350px;left:0px;border-style:solid;border-color:#444444;border-width:3px;"
divs[15]["style"] = "width:900px;height:600px;position:absolute;top:1350px;left:600px;border-style:solid;border-color:#444444;border-width:3px;"
divs[16]["style"] = "width:750px;height:500px;position:absolute;top:1950px;left:0px;border-style:solid;border-color:#444444;border-width:3px;"
divs[17]["style"] = "width:750px;height:500px;position:absolute;top:1950px;left:750px;border-style:solid;border-color:#444444;border-width:3px;"
body = html_bf.find("body")
body["style"] = "background-color:#333333;"
div_title="<div align=\"center\" style=\"width:1500px;\">\n<span style=\"font-size:32px;font face=\'黑体\';color:#FFFFFF\"><b>用户流失因素探索</b></div>"
#修改页面背景色、追加标题
body.insert(0,BeautifulSoup(div_title,"lxml").div)
html_new = str(html_bf)
html.seek(0, 0)
html.truncate()
html.write(html_new)
html.close()
div这个列表里就是你所有的图,我这里有18个图,按顺序对应div列表第0到17个元素(按道理应该是这样,但是我这里5和13顺序乱了,做完记得注意一下就行)
divs[x][“style”] 按顺序指定的分别是图宽度,高度,与上边距距离,与左边距距离,边框的颜色,边框的粗细
body[“style”] 就是整个页面的背景色,最好和你的图背景色一样吧,好看点