问题描述
我已经使用 vedo
库生成了一个网络图,我正在尝试将其作为插图添加到 matplotlib
中生成的图
import networkx as nx
import matplotlib.pyplot as plt
from vedo import *
from matplotlib.offsetbox import OffsetImage,AnnotationBbox
G = nx.gnm_random_graph(n=10,m=15,seed=1)
nxpos = nx.spring_layout(G,dim=3,seed=1)
nxpts = [nxpos[pt] for pt in sorted(nxpos)]
nx_lines = [(nxpts[i],nxpts[j]) for i,j in G.edges()]
pts = Points(nxpts,r=12)
edg = Lines(nx_lines).lw(2)
# node values
values = [[1,0],[30,80,10,79,70,60,75,78,65,10],[1,.30,.10,.79,.70,.60,.75,.78,.65,.90]]
time = [0.0,0.1,0.2] # in seconds
vplt = Plotter(N=1)
pts1 = pts.cmap('Blues',values[0])
vplt.show(
pts1,edg,axes=False,bg='white',at=0,interactive=False,zoom=1.5
).screenshot("network.png")
ax = plt.subplot(111)
ax.plot(
[1,2,3],'go-',label='line 1',linewidth=2
)
arr_img = vplt.screenshot(returnNumpy=True,scale=1)
im = OffsetImage(arr_img,zoom=0.25)
ab = AnnotationBbox(im,(1,0),xycoords='axes fraction',box_alignment=(1.1,-0.1),frameon=False)
ax.add_artist(ab)
plt.show()
ax.figure.savefig(
"output.svg",transparent=True,dpi=600,bbox_inches="tight"
)
插图中的图像分辨率太低。关于如何在不损失分辨率的情况下添加插图的建议将非常有帮助。
编辑: 下面发布的答案适用于添加 2D 网络,但我仍在寻找有助于在插图中添加 3D 网络的方法。
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)