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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T13:14:46+00:00 2026-05-13T13:14:46+00:00

So I’m representing a token ring network (doing the simulation in SimPy), I’m a

  • 0

So I’m representing a token ring network (doing the simulation in SimPy), I’m a totally newbie to matplotlib, but I was told that it’d be really good for representing my simulation visually.

So I googled around and found out how to draw shapes and lines – using add_patch and add_line respectively to the axes (I believe). So now I have this output which is absolutely fine:

(can’t post images yet!!)
http://img137.imageshack.us/img137/7822/screenshot20100121at120.png

But I’m getting this using the pylab.show() function, and what I think I want is to achieve this using the pylab.plot() function so that I can then update it as my simulation progresses using pylab.draw() afterward.

My code is as follows:

plab.ion()

plab.axes()

for circ in self.circleList:
    plab.gca().add_patch(circ)

for line in self.lineList:
    plab.gca().add_line(line)

plab.axis('scaled')
plab.show()

Where circleList and lineList are lists containing the circles and lines on the diagram

I’m probably misunderstanding something simple here, but I can’t actually find any examples that aren’t overtly graph based that use the plot() function.


Clarification:

How can I get that same output, using pylab.plot() instead of pylab.show() ?

  • 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-13T13:14:46+00:00Added an answer on May 13, 2026 at 1:14 pm

    Replicating your image using the plot method:

    from pylab import *
    
    points = []
    points.append((-0.25, -1.0))
    points.append((0.7, -0.7))
    points.append((1,0))
    points.append((0.7,1))
    points.append((-0.25,1.2))
    points.append((-1,0.5))
    points.append((-1,-0.5))
    points.append((-0.25, -1.0))
    
    a_line = plot(*zip(*points))[0]
    a_line.set_color('g')
    a_line.set_marker('o')
    a_line.set_markerfacecolor('b')
    a_line.set_markersize(30)
    axis([-1.5,1.5,-1.5,1.5])
    
    show()
    

    EDIT BASED ON COMMENTS

    This uses python multiprocessing library to run the matplotlib animation in a separate process. The main process uses a queue to pass data to it which then updates the plot image.

    # general imports
    import random, time
    from multiprocessing import Process, Queue
    
    # for matplotlib
    import random
    import numpy as np
    import matplotlib
    matplotlib.use('GTKAgg') # do this before importing pylab
    
    import matplotlib.pyplot as plt
    from matplotlib.patches import Circle
    
    
    def matplotLibAnimate(q,points):
    
        # set up initial plot
        fig = plt.figure()
        ax = fig.add_subplot(111)
    
    
        circles = []
        for point in points:
            ax.add_patch(Circle(point,0.1))
    
        a_line, = ax.plot(*zip(*points))
        a_line.set_color('g')
        a_line.set_lw(2)
    
        currentNode = None  
        def animate(currentNode = currentNode):
            while 1:
                newNode = q.get()
                if currentNode: currentNode.remove()
                circle = Circle(newNode,0.1)
                currentNode = ax.add_patch(circle)
                circle.set_fc('r')
                fig.canvas.draw()
    
        # start the animation
        import gobject
        gobject.idle_add(animate)
        plt.show()
    
    #initial points
    points = ((-0.25, -1.0),(0.7, -0.7),(1,0),(0.7,1),(-0.25,1.2),(-1,0.5),(-1,-0.5),(-0.25, -1.0))
    q = Queue()
    p = Process(target = matplotLibAnimate, args=(q,points,))
    p.start()
    
    # feed animation data
    while 1:
        time.sleep(random.randrange(4))
        q.put(random.sample(points,1)[0])
    

    Of course, after doing this I think you’ll be better served with whatnick’s image solution. I’d create my own GUI and not use matplotlibs built in widget. I’d then “animate” my GUI by generating PNGs and swapping them.

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

Sidebar

Ask A Question

Stats

  • Questions 316k
  • Answers 316k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer "[I]t examines the Class type passed in through a method… May 13, 2026 at 11:24 pm
  • Editorial Team
    Editorial Team added an answer It appears that there is an error in Win32::IE::Mechanize version… May 13, 2026 at 11:24 pm
  • Editorial Team
    Editorial Team added an answer You should be able to put the byte[] into a… May 13, 2026 at 11:24 pm

Related Questions

I want use html5's new tag to play a wav file (currently only supported
In order to apply a triggered animation to all ToolTip s in my app,
this is what i have right now Drawing an RSS feed into the php,
I have text I am displaying in SIlverlight that is coming from a CMS
I have a French site that I want to parse, but am running into

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.