Ask Your Question
0

how display labels edges and color with dictionary? ​

asked 2024-02-26 13:08:37 +0100

ortollj gravatar image

Hi

How can I label edges style :edge (0,1) ='01' and give them a color like in the simplex1ColorRevDic dictionary ?

# functions
def strListToList(strL) :
    Lstr=strL.replace('[','').replace(']','').split(',')
    return [SR(e) for e in Lstr]

def addAxis(plt,textToPlt,xBound,yBound,zBound,wA,rA) :
    # add axis for real part
    plt += arrow3d((0, 0, 0), (xBound, 0, 0), color='red',width=wA,radius=rA)
    plt += text3d("ex", (xBound, 0, 0), fontsize='200%', color='black')
    plt += arrow3d((0, 0, 0), (0, yBound, 0), color='gray',width=wA,radius=rA)
    plt += text3d("ey", (0, yBound, 0), fontsize='200%', color='gray')
    plt += arrow3d((0, 0, 0), (0, 0, zBound), color='pink',width=wA,radius=rA)
    plt += text3d("ez", (0,0, zBound), fontsize='200%', color='pink')
    plt+=textToPlt
    return plt



xBound=1.5 ;yBound=1.5 ;zBound=1.5
shiftV=vector([1/10,1/10,1/10])
widthA=0.2 ;radiusA=0.02
textToPlt = text3d("test",vector( (xBound, yBound, 1.5*zBound))+shiftV, fontsize='300%', fontweight=800)

g = DiGraph()




cubeDic={0: [0, 0, 0],1: [1, 0, 0], 2: [0, 1, 0], 3: [1, 1, 0] , 
          4: [0, 0, 1], 5: [1, 0, 1], 6: [0, 1, 1], 7: [1, 1, 1]}

simplex0=[ 0, 1, 2, 3, 4, 5, 6, 7 ]
simplex1=[[0, 4], [0, 5], [0, 6], [4, 5], [4, 6],
          [5, 6], [0, 1], [0, 3], [0, 7], [1, 3],
          [1, 7], [3, 7], [1, 5], [5, 7], [0, 2],
          [2, 3], [2, 6], [3, 6], [6, 7]]

colorPaletteSimplex1=rainbow(len(simplex1))
simplex1ColorDic={}

for v,c  in zip(simplex1,colorPaletteSimplex1):
    simplex1ColorDic[str(v)]=str(c)

keys=[simplex1ColorDic.get(k) for k in simplex1ColorDic.keys()]
values=[strListToList(s1)for s1 in simplex1ColorDic.keys()]

simplex1ColorRevDic=dict(zip(keys,values))    

g.add_vertices( simplex0 )

g.add_edges(simplex1)
g.set_edge_label((0,1),'toto',(0,0.5,0))
g.set_pos(cubeDic,dim=3)
print('positions :',g.get_pos(dim=3))
#gPlt=g.plot3d(save_pos=True,edge_colors=simplex1ColorRevDic) #errors !
gPlt=g.plot3d(save_pos=True,edge_labels=True)
gPlt=addAxis(gPlt,textToPlt,xBound,yBound,zBound,widthA,radiusA)
gPlt.show()
edit retag flag offensive close merge delete

Comments

It seems that plot3d is not able to display the labels .

newLabels=[]
for e in g.edges(sort=True) :
    ec=list(copy(e))
    ec[2]=str(ec[0])+str(ec[1])
    newLabels.append(ec)
newLabels
for v0,v1,l in newLabels :
    g.set_edge_label(v0,v1,l)

gPlt=g.plot3d(save_pos=True,edge_labels=True)
gPlt=addAxis(gPlt,textToPlt,xBound,yBound,zBound,widthA,radiusA)
gPlt.show()

g.edges(sort=True)
ortollj gravatar imageortollj ( 2024-02-27 06:04:34 +0100 )edit

1 Answer

Sort by » oldest newest most voted
0

answered 2024-02-27 08:53:10 +0100

ortollj gravatar image

updated 2024-02-27 09:01:32 +0100

I did this little workaround:

def g3dPlot(g,colorsDic) :    
    plt=Graphics()
    locationDic=g.get_pos(dim=3)
    for edge in g.edges(sort=True) :

        colorV=colorsDic.get(str([edge[0],edge[1]]))
        vStart=vector(locationDic.get(edge[0]));vEnd=vector(locationDic.get(edge[1]))
        plt+=arrow3d(vStart,vEnd,width=2,radius=0.02,color=colorV )
        posText=(vEnd-vStart)/2 + vStart  + shiftV
        plt+= text3d(edge[2],posText, fontsize='100%', fontweight=50,color=colorV)        
    return plt
gColorPlt=g3dPlot(g,simplex1ColorDic)
gColorPlt=addAxis(gColorPlt,textToPlt,xBound,yBound,zBound,widthA,radiusA)
gColorPlt.show()

sageCell

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2024-02-26 13:08:37 +0100

Seen: 165 times

Last updated: Feb 27