Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3485278
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T10:53:18+00:00 2026-05-18T10:53:18+00:00

I’ve built a tree image, see question . Now I’ve some major groups. One

  • 0

I’ve built a tree image, see question.
Now I’ve some major groups.
One group has nodes with color green and brown, and has a ‘B’ and a ‘A’. The second group has only pink nodes and ‘T’ and the last group has yellow, orange and blue, and the letters ‘L’, ‘X’ and ‘H’. the colors refer to the colors of the nodes and the letters belong to the name. So I want to color the edge of the different groups.

#taken from draw_graphviz
def get_label_mapping(G, selection): 
    for node in G.nodes(): 
        if (selection is None) or (node in selection): 
            try: 
                label = str(node) 
                if label not in (None, node.__class__.__name__): 
                    yield (node, label) 
            except (LookupError, AttributeError, ValueError): 
                pass


labels = dict(get_label_mapping(G, None))
for label in labels.keys():
if str(label) != "Clade":
        num = label.name.split('-')
        if 'T' in num[0]:
            node_colors.append('#CC6699')
        elif 'X' in num[0]:
            node_colors.append('r')
        else:
            node_colors.append('y')

so I’ve done a similar function to the above, instead of node, I changed to get_edge.
and try this:

  for edge in edges.keys():
        if str(edge) != "Clade":
            if 'T' in edge:
                edge_colors.append('b')

where edge is:

(Clade(branch_length=-0.00193, name='T-7199-8'), Clade(branch_length=0.00494))

perhaps there’s a way to say if T is in name, then color the edge.
What to you think?

anyone knows how to do this?

Thank you

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T10:53:19+00:00Added an answer on May 18, 2026 at 10:53 am

    I’m guessing (since I don’t know how that snippet fits in to the rest of the code) that you’re iterating over the nodes, and adding one colour to the list for each node. Like the error message suggests, you need to work out the colour required for each edge. That’s going to be trickier.

    Alright, got it! The code could be tidied up a bit, but this works.

    #Define your centre node: you need to pull this out of the graph. Call it b.
    # The number changes each time: look for a Clade(branch_length=0.03297)
    # Its neighbors have branch lengths .00177, .01972, .00774.
    b = G.nodes()[112]
    
    # Recursively paint edges below a certain point, ignoring ones we've already seen
    def paintedges(graph, startnode, colour):
        for node in graph.neighbors(startnode):
            if node not in alreadyseen: # alreadyseen is in global scope
                graph[startnode][node]["colour"] = colour
                alreadyseen.add(node)
                paintedges(graph, node, colour)
    
    alreadyseen = set([b])
    G[b][G.neighbors(b)[0]]["colour"] = "red"
    paintedges(G, G.neighbors(b)[0], "red")
    G[b][G.neighbors(b)[1]]["colour"] = "blue"
    paintedges(G, G.neighbors(b)[1], "blue")
    G[b][G.neighbors(b)[2]]["colour"] = "green"
    paintedges(G, G.neighbors(b)[2], "green")
    
    # Now make a list of all the colours, in the order networkx keeps the edges
    edgecolours = [G[f][t]["colour"] for f,t in G.edges()]
    kwargs["edge_color"] = edgecolours
    

    Tree with colours

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a jquery bug and I've been looking for hours now, I can't
Basically, what I'm trying to create is a page of div tags, each has
I've got a string that has curly quotes in it. I'd like to replace
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.