?
#关系可视化
from pyecharts import options as opts
from pyecharts.charts import Graph
from pyecharts.globals import ThemeTypeimport webbrowser#生成大量节点
nodes=[]
for i in range(20):#node={"name":"节点"+str(i),"symbolsize":20}node=opts.GraphNode(name="节点"+str(i), #节点名称 ★ 不能有重名!symbol_size=10+i, #节点大小symbol='image://cat_brown.svg' #★★★★★ 节点样式可选:'circle', 'rect', 'roundRect', 'triangle', 'diamond', 'pin', 'arrow', 'none', 'image://url')nodes.append(node)#节点间连接线样式设置
linestyle_opts=opts.LineStyleOpts(is_show=True,width=1,opacity=0.6,curve=0.3,type_="solid", color="red" )#连接所有节点
links = []
for i in nodes:for j in nodes: source_node_name=i.get("name")target_node_name=j.get("name") links.append({"source":source_node_name,"target":target_node_name,"lineStyle":linestyle_opts})#主要设置
#InitOpts:初始化配置项(在图形创建开始时即可设置)
init_opts=opts.InitOpts(width="100%", #图宽height="900px", #图高renderer="canvas", #渲染模式 svg 或 canvas,即 RenderType.CANVAS 或 RenderType.SVGpage_title="Pyecharts Graph关系图", #网页标题theme=ThemeType.DARK, #主题风格可选:WHITE,LIGHT,DARK,CHALK,ESSOS,INFOGRAPHIC,MACARONS,PURPLE_PASSION,ROMA,ROMANTIC,SHINE,VINTAGE,WALDEN,WESTEROS,WONDERLAND#bg_color="#333333", #背景颜色js_host="" #js主服务位置 留空则默认官方远程主服务)#ToolboxOpts:工具栏配置(可实现图片保存等功能)
toolbox_opts=opts.ToolboxOpts(is_show=True, #是否显示工具栏orient="vertical", #工具栏工具摆放方向pos_left="right") #工具栏左边位置#★★★★★
#通过opts.ItemStyleOpts,设置node节点样式(颜色、大小、透明度)
itemstyle_opts=opts.ItemStyleOpts(color="orange", #节点颜色border_color="red", #节点边线颜色border_width=1, #节点边线宽度opacity=0.9) #节点透明度c = (Graph(init_opts).add("", nodes, links, repulsion=8000,itemstyle_opts=itemstyle_opts,is_draggable=True).set_global_opts(title_opts=opts.TitleOpts(title="Pyecharts Graph 示例"),toolbox_opts=toolbox_opts).render("graph.html")
)#---------------------------------------#---------------------------------------from flask import Flask,g,request,render_template,Response,stream_with_context
import threading
import time#---------------------------------------
app=Flask(__name__,static_url_path='',template_folder='',static_folder='')@app.route('/')
def index():return render_template("graph.html")#---------------------------------------def run_app():print("应用启动")if __name__ == '__main__':app.run("0.0.0.0")def open_browser():time.sleep(1)print("打开浏览器")webbrowser.open("http://localhost:5000")def main():#主要程序# 创建线程thread1 = threading.Thread(target=open_browser)thread2 = threading.Thread(target=run_app)# 启动线程thread1.start()thread2.start()if __name__ == '__main__':main()?