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

  • SEARCH
  • Home
  • 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 7769215
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T16:06:14+00:00 2026-06-01T16:06:14+00:00

I have created a directed graph and through a program i am finding out

  • 0

I have created a directed graph and through a program i am finding out all the cycles it contains. After creating the graph i want to change the colour of the edges which contain the vertices involved in the cycle.

I am using python igraph.

Please Help

  • 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-06-01T16:06:15+00:00Added an answer on June 1, 2026 at 4:06 pm

    Something like this:

    vertex_set = set(vertices_in_cycle)
    g.es["color"] = "black"
    red_edges = g.es.select(_source_in=vertex_set, _target_in=vertex_set)
    red_edges["color"] = "red"
    

    Explanation:

    1. g.es represents the set of all edges in the graph. (Similarly, g.vs is the set of all vertices).

    2. g.es["color"] lets you assign a value to the color attribute of all the edges in the graph. This edge attribute is used by the plotter to decide what color an edge should have. Therefore, in line 2, you are setting the color of all the edges to black. (Note: you could also use a list here instead of a simple string, or you could use HTML color notations for custom colors).

    3. You could use g.es as a list, in which case you get a particular edge of the graph; e.g., g.es[2] would give you the edge with id=2. This is not used here, but it’s good to know.

    4. g.es.select is a method that selects a subset of the edges based on some criteria. help(EdgeSeq.select) gives you more info about this; the point here is that in line 3, you are selecting all the edges for which both endpoints lie in the vertex set you are interested in. The selected edges are stored in the red_edges variable, which has the same type as g.es (i.e. EdgeSeq).

    5. In the last row, you are setting the color of all the edges in red_edges to red, overriding the black color you have set in line 2.

    Note that the above code will paint not only the edges of the cycle to red but also all the chords of the cycle.

    Update: if line 3 in the above code does not work for you for some reason, you can replace lines 2 and 3 with the following:

    g.es["color"] = ["red" if (edge.source in vertex_set and \
                               edge.target in vertex_set) else "black" \
                     for edge in g.es]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have created a user page with a menu that contains a logout button.
Let G be an unweighted directed graph containing cycles. I'm looking for an algorithm
I have the following data set, which represents nodes in a directed graph. CREATE
I have a directed graph data structure, where I am trying to implement individual
I have created a testing Google Analytics sample app as directed in on Google
Have created a c++ implementation of the Hough transform for detecting lines in images.
I have created a template for Visual Studio 2008 and it currently shows up
I have created a custom dialog for Visual Studio Setup Project using the steps
I have created a PHP-script to update a web server that is live inside
I have created a UserControl that has a ListView in it. The ListView is

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.