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 8962263
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T16:05:38+00:00 2026-06-15T16:05:38+00:00

I am trying to visualize a connection matrix of an bi-partite set problem. How

  • 0

I am trying to visualize a connection matrix of an bi-partite set problem. How do i do this in a way that demonstrates best?

I have started with this using a graphics program yed:

example

The circles describe a certain kind of connection between red and blue and the squares another. Both red and blue squares will have some kind of text on them.

However it would be nicer to generate this grafic with matplotlib, since i would like to generate this on the fly with data attached. How would i proceed to do that?
My data looks kinda like this:

Data:

name_blue name_red Connection Type
bluepart1 redpart1 1
bluepart1 redpart2 1
bluepart1 redpart3 1
bluepart3 redpart2 2 
bluepart4 redpart2 2
...

and so on. I would like to write the nametags onto the blue/red squares, so that the user knows which is which.

Followup question:
How can i generate a graph from this with the nodes partly marked blue/red? Kind of like this:

graphexample

But with the nodes reflecting their bipartite nature. I am still a bit in the dark on this, mainly because i don’t know how to tackle this with matplotlib. I am hoping for a few good suggestions on how to visualize this and maybe an example implementation that shows me the way.

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

    What about doing a bipartite representation with color edges like this?

    Bipartite graph with different kinds of connections

    Following is the code that generated the image.

    import matplotlib.pyplot as plt
    
    def addconnection(i,j,c):
      return [((-1,1),(i-1,j-1),c)]
    
    def drawnodes(s,i):
      global ax
      if(i==1):
        color='r'
        posx=1
      else:
        color='b'
        posx=-1
    
      posy=0
      for n in s:
        plt.gca().add_patch( plt.Circle((posx,posy),radius=0.05,fc=color))
        if posx==1:
          ax.annotate(n,xy=(posx,posy+0.1))
        else:
          ax.annotate(n,xy=(posx-len(n)*0.1,posy+0.1))
        posy+=1
    
    ax=plt.figure().add_subplot(111)
    set1=['Man1','Man2','Man3','Man4']
    set2=['Woman1','Woman2','Woman3','Woman4','Woman5']
    plt.axis([-2,2,-1,max(len(set1),len(set2))+1])
    frame=plt.gca()
    frame.axes.get_xaxis().set_ticks([])
    frame.axes.get_yaxis().set_ticks([])
    
    drawnodes(set1,1)
    drawnodes(set2,2)
    
    connections=[]
    connections+=addconnection(1,2,'g')
    connections+=addconnection(1,3,'y')
    connections+=addconnection(1,4,'g')
    connections+=addconnection(2,1,'g')
    connections+=addconnection(4,1,'y')
    connections+=addconnection(4,3,'g')
    connections+=addconnection(5,4,'y')
    
    for c in connections:
      plt.plot(c[0],c[1],c[2])
    
    plt.show()
    

    To get something like what your are drawing in yEd

    Connection matrix

    import matplotlib.pyplot as plt
    
    COLOR1='r'
    COLOR2='b'
    
    def addconnection(i,j,c):
      if(c==1):
        plt.gca().add_patch( plt.Rectangle((j-0.1,-i-0.1),0.2,0.2,fc='y'))
      if(c==2):
        plt.gca().add_patch( plt.Circle((j,-i),radius=0.1,fc='y'))
    
    def drawnodes(s,i):
      global ax
      if(i==1):
        color=COLOR1
        vx=1
        vy=0
      else:
        color=COLOR2
        vx=0
        vy=1
    
      step=1
      for n in s:
        posx=step*vx
        posy=step*vy
    
        plt.gca().add_patch( plt.Circle((posx,-posy),radius=0.1,fc=color))
        ax.annotate(n,xy=(posx-len(n)*0.1,-posy+0.15))
        step+=1
    
    f=open('input.txt')
    t=f.readlines()
    t=map(lambda x: x.replace('(',' ').replace(')',' ').split(':'),t)
    
    set1=set([])
    set2=set([])
    
    for x in t:
      s=x[1].split()
      set1.add(s[0])
      set2.add(s[1])
    
    set1=list(set1)
    set2=list(set2)
    
    dic={}
    for e in zip(set1,xrange(1,len(set1)+1)): dic[(e[0],1)]=e[1]
    for e in zip(set2,xrange(1,len(set2)+1)): dic[(e[0],2)]=e[1]
    
    ax=plt.figure(figsize=(max(len(set1),len(set2))+1,max(len(set1),len(set2))+1)).add_subplot(111)
    plt.axis([-1,max(len(set1),len(set2))+1,-max(len(set1),len(set2))-1,1])
    frame=plt.gca()
    frame.axes.get_xaxis().set_ticks([])
    frame.axes.get_yaxis().set_ticks([])
    
    drawnodes(set1,1)
    drawnodes(set2,2)
    
    for x in t:
      s=x[1].split()
      addconnection(dic[(s[0],1)],dic[(s[1],2)],int(x[2]))
    
    plt.show()
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a very large possible data set that I am trying to visualize
I am trying to visualize my matrix class in a more readable way than
I'm trying to visualize Mandelbrot set with OpenGL and have found very strange behaviour
I'm trying to visualize some data I have stored on a regular grid using
I just started trying to visualize my data by using the ggplot2 package in
I have some data about a day's events that I'm trying to visualise as
Trying to make this jQuery filter that uses .find case-insensitive. For example, when the
I am having a hard time getting started with some way to visualize some
In my WPF application im trying to visualize some temperature data. I have a
I've started learning about image processing in Matlab and I have a small problem.

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.