python绘制马尔可夫链,但是存在一些问题,E1–>E1的边小的看不见,不知道如何解决?
import numpy as np
P=np.array([[0.181, 0.454, 0.363],
[0.555, 0.111, 0.333],
[0.333, 0.444, 0.222]])
data=['E1','E2','E3']
for i in range(len(data)):
for j in range(len(data)):
print("opts.GraphLink(source='%s', target='%s', value=%s),"%(data[i],data[j],P[i][j]))
from pyecharts import options as opts
from pyecharts.charts import Graph
from pyecharts.render import make_snapshot
from pyecharts import options as opts
from pyecharts.charts import Graph
nodes = [
opts.GraphNode(name="E1", symbol_size=20),
opts.GraphNode(name="E2", symbol_size=20),
opts.GraphNode(name="E3", symbol_size=20),
]
links = [
opts.GraphLink(source='E1', target='E1', value=0.181),
opts.GraphLink(source='E1', target='E2', value=0.454),
opts.GraphLink(source='E1', target='E3', value=0.363),
opts.GraphLink(source='E2', target='E1', value=0.555),
opts.GraphLink(source='E2', target='E2', value=0.111),
opts.GraphLink(source='E2', target='E3', value=0.333),
opts.GraphLink(source='E3', target='E1', value=0.333),
opts.GraphLink(source='E3', target='E2', value=0.444),
opts.GraphLink(source='E3', target='E3', value=0.222),
]
c = (
Graph()
.add("", nodes,links,
edge_symbol=['circle', 'arrow'],
repulsion=40000,
edge_length=0.0001,
is_draggable=True,
linestyle_opts=opts.LineStyleOpts(curve=0.3, opacity=0.5),
edge_label=opts.LabelOpts(
is_show=True, position="middle", formatter='{c}',
font_size=20,
color='black'
),
)
.set_global_opts(title_opts=opts.TitleOpts(title="马尔科夫链"))
)
c.render_notebook()
|