Pyecharts Graph 关系图示例

​
#关系可视化
from pyecharts import options as opts
from pyecharts.charts import Graph
from pyecharts.globals import ThemeType

import 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,
      
  • 0
    点赞
  • 13
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
`label_opts`是`pyecharts`中用于设置节点标签的配置参数,`tooltip_formatter`是用于设置表的提示框格式化函数。 `label_opts`主要用于设置节点标签的样式和显示内容,它是一个字典类型的参数,可以设置以下几个属性: 1. `position`:设置标签相对节点的位置,默认为'inside',可以设置为'inside'、'top'、'bottom'、'left'、'right'、'insideLeft'、'insideRight'、'insideTop'、'insideBottom'、'insideTopLeft'、'insideTopRight'、'insideBottomLeft'、'insideBottomRight'等值。 2. `offset`:设置标签在x轴和y轴上的偏移量,默认为[0,0]。 3. `font_style`:设置标签的字体样式,默认为'normal'。 4. `font_weight`:设置标签的字体粗细,默认为'normal'。 5. `font_size`:设置标签的字体大小,默认为'12'。 6. `color`:设置标签的字体颜色,默认为'#666'。 7. `rotate`:设置标签的旋转角度,默认为0,表示不旋转。 `tooltip_formatter`是用于设置表的提示框格式化函数,它是一个函数对象,可以自定义函数的内容。在函数中,可以使用格式化字符串,如`{b}`表示节点名称,`{c}`表示节点值,`{d}`表示节点在数据中的索引等。 例如,可以通过设置`label_opts`来更改节点标签的显示位置和样式: ```python from pyecharts import options as opts from pyecharts.charts import Graph # 创建节点标签配置 label_opts = { "position": "top", "offset": [0, 0], "font_style": "normal", "font_weight": "normal", "font_size": 12, "color": "#666", "rotate": 0 } # 创建graph = Graph() graph.add("", nodes, links, label_opts=label_opts) # 显示graph.render() ``` 可以通过设置`tooltip_formatter`来自定义提示框的显示内容: ```python from pyecharts import options as opts from pyecharts.charts import Graph # 创建提示框格式化函数 def formatter(params): return "节点名称:" + params['name'] + "<br>" + \ "节点值:" + str(params['value']) + "<br>" + \ "节点索引:" + str(params['dataIndex']) # 创建graph = Graph() graph.add("", nodes, links, tooltip_formatter=formatter) # 显示graph.render() ``` 上述代码中的`nodes`和`links`分别表示节点和边的数据,具体数据格式请参考`pyecharts`的文档。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值