DiGraph, Latex, and same orientation

asked 2019-10-02 05:46:03 -0500

ortollj gravatar image

updated 2019-10-06 06:14:50 -0500

Hi

1) is it possible to write in Latex in vertices and edges ?

2) depending on whether I set the value of the Population variable to 1000 or to 100000 it swaps the branches sick and not sick, so is it a possibility to keep the same orientation each time ?

p=1000 ;print "Population : "+str(p)
sr=1/1000 ;print "Sick Rate : "+str(sr)
pfr=95/100 ;print "Positive False Rate : "+str(pfr*100)+'/'+"100"
nfr=40/100 ;print "Negative False Rate : "+str(nfr*100)+'/'+"100"
PbNS=(p-p*sr)*(1-pfr);print "Positive but Not Sick : "+str(round((p-p*sr)*(1-pfr),5))
PaS=((p-(1-sr)*p))*(1-nfr); print "Positive and Sick : ",str(round(((p-(1-sr)*p))*(1-nfr),5))
print "chance to be Sick if Tested Positive : ",PaS/(PbNS+PaS)," about :",round((PaS/(PbNS+PaS)),5)," : ",\
    round((PaS/(PbNS+PaS))*100,5),"%"
H0=DiGraph({0:[1,2], 1:[3,4], 2:[5,6]})
#H.set_latex_options(edge_labels=True)
H0.set_edge_label(0, 1, "Not Sick : "+str(p-sr*p)+"/" +str(p))
H0.set_edge_label(0, 2, "Sick: "+str((p-(1-sr)*p))+'/'+str(p))
# not sick branch
H0.set_edge_label(1, 3, "Not Sick \n Tested Negative: "+str(pfr*100)+'/'+"100")
H0.set_edge_label(1, 4, "\n\n\n Not Sick \n Tested Positive: "+str((1-pfr)*100)+'/'+"100")
# sick branch
H0.set_edge_label(2, 5, "Sick Tested Negative: "+str((nfr)*100)+'/'+"100")
H0.set_edge_label(2, 6, "\n\n\n\nSick Tested Positive: \n "+str((1-nfr)*100)+'/'+"100")
H0.relabel({0:str(p)+' Peoples' , 1:str(p-p*sr), 2:str(p-p*(1-sr)), \
           3:str(round((p-p*sr)*pfr,5))+' \n Tested Negative and Not Sick', \
           4:str(round((p-p*sr)*(1-pfr),5))+' \n Tested positive but Not Sick', \
           5:str(round(((p-(1-sr)*p))*(nfr),5))+' \n Tested Negative and  Sick', \
           6:str(round(((p-(1-sr)*p))*(1-nfr),5))+' \n Tested Positive and  Sick'})
H0.show(vertex_color='white', vertex_shape='_',edge_labels=True,figsize=[10,10],layout='tree')

[edited the 2019/10/06, below attempt to solve pb with get_pos(),see David Coudert comment] it seems that get_pos() does not get something ?:

def ShowTreeH0(p,H0Vert,H0Pos):
    sr=1/1000 ;print "Sick Rate : "+str(sr)
    pfr=95/100 ;print "Positive False Rate : "+str(pfr*100)+'/'+"100"
    nfr=40/100 ;print "Negative False Rate : "+str(nfr*100)+'/'+"100"
    PbNS=(p-p*sr)*(1-pfr);print "Positive but Not Sick : "+str(round((p-p*sr)*(1-pfr),5))
    PaS=((p-(1-sr)*p))*(1-nfr); print "Positive and Sick : ",str(round(((p-(1-sr)*p))*(1-nfr),5))
    print "chance to be Sick if Tested Positive : ",PaS/(PbNS+PaS)," about :",round((PaS/(PbNS+PaS)),5)," : ",\
        round((PaS/(PbNS+PaS))*100,5),"%"
    H0=DiGraph({0:[1,2], 1:[3,4], 2:[5,6]})
    #H.set_latex_options(edge_labels=True)
    H0.set_edge_label(0, 1, "Not Sick : "+str(p-sr*p)+"/" +str(p))
    H0.set_edge_label(0, 2, "Sick: "+str((p-(1-sr)*p))+'/'+str(p))
    # not sick branch
    H0.set_edge_label(1, 3, "Not Sick \n Tested Negative: "+str(pfr*100)+'/'+"100")
    H0.set_edge_label(1, 4, "\n\n\n Not Sick \n Tested Positive: "+str((1-pfr)*100)+'/'+"100")
    # sick branch
    H0.set_edge_label(2, 5, "Sick Tested Negative: "+str((nfr)*100)+'/'+"100")
    H0.set_edge_label(2, 6, "\n\n\n\nSick Tested Positive: \n "+str((1-nfr)*100)+'/'+"100")
    H0.relabel({0:str(p)+' Peoples' , 1:str(p-p*sr), 2:str(p-p*(1-sr)), \
               3:str(round((p-p*sr)*pfr,5))+' \n Tested Negative and Not Sick', \
               4:str(round((p-p*sr)*(1-pfr),5))+' \n Tested positive but Not Sick', \
               5:str(round(((p-(1-sr)*p))*(nfr),5))+' \n Tested Negative and  Sick', \
               6:str(round(((p-(1-sr)*p))*(1-nfr),5))+' \n Tested Positive and  Sick'})
    if H0Vert<>None and H0Vert<>None :
        print " set vertice and position"
        H0.set_vertices(H0Vert)
        H0.set_pos(H0Pos)   

    H0.show(vertex_color='white', vertex_shape='_',edge_labels=True,figsize=[10,10],layout='tree')
    return H0.get_vertices(),H0.get_pos()
H0Vert=None
H0Pos=None
p=1000 ;print "Population : "+str(p)
H0Vert,H0Pos=ShowTreeH0(p,H0Vert,H0Pos)
p=100000 ;print "Population : "+str(p)
H0Vert,H0Pos=ShowTreeH0(p,H0Vert,H0Pos)
edit retag flag offensive close merge delete

Comments

Have you tried latex(H0) ? For 2), you can simply set the position of vertices using H0.set_pos(...) instead of relying on the layout.

David Coudert gravatar imageDavid Coudert ( 2019-10-05 10:41:27 -0500 )edit

Hi David

Have you tried latex(H0) ? are you sure it is ok ?

Imagine I want to show only in vertex 6 : $\sqrt{2}$ (could you precise me What I need to do ? I tried 6:LatexExpr(latex(sqrt(2)))+' \n Tested Positive and Sick'}) without success

ortollj gravatar imageortollj ( 2019-10-06 03:41:59 -0500 )edit

Oops ok I see what you mean, I I do latex(H0) and in the Latex code I change the text value with \sqrt{2}

ortollj gravatar imageortollj ( 2019-10-06 03:48:40 -0500 )edit