473,729 Members | 2,405 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Realtime interactive graphing of a simulation

7 New Member
I am writing a program to simulate a double displacement reaction getting to equilibrium, but I am having some trouble graphing the particles' concentrations. It seems that it's only possible to pan and zoom the graph once the program exits (when running it from IDLE), but I don't want to have to kill the sim every time I want to view the graph (besides, when I do, the graph window dissappears).

The following code contains all the graphing functionality, the initGraph() function is called before the sim's main loop, and updateGraph() is called once a second with the current concentrations of 4 types of particles. The sim uses PyGame for graphics, and I didn't think that code was relevant: if it is, just let me know and I'll post it.

Expand|Select|Wrap|Line Numbers
  1. from pylab import *
  2.  
  3. # Turn on interactive mode for graphing
  4. ion()
  5. #hold(False)
  6. xlabel("time (seconds)")
  7. ylabel("concentration (particles/window)")
  8.  
  9. #graphLines = []
  10. graphData = []
  11. updateInterval = 0
  12.  
  13. def initGraph(interval, *colours):
  14.     """Initializes this module
  15.  
  16.     interval: the time, in seconds, btwn calls to updateGraph()
  17.     colours: list of 3-tuples (r,g,b) for each line's colour
  18.     """
  19.     updateInterval = interval
  20.     for c in colours:
  21.         line = plot([0],[0])[0]
  22.         line.set_color(c)
  23.         graphData.append({'x':[0],'y':[0]})
  24.         #graphLines.append(line)
  25.  
  26. def updateGraph(*cons):
  27.     """Updates graph data and draws it
  28.  
  29.     cons: a list of concentrations, the same length of colours arg to initGraph
  30.     """
  31.     #for line, con in zip(graphLines, cons):
  32.     for line, con in zip(graphData, cons):
  33.         #xdata, ydata = line.get_xdata(), line.get_ydata()
  34.         #xdata.append(xdata[-1] + updateInterval)
  35.         #ydata.append(con)
  36.         #line.set_data(xdata, ydata)
  37.         #plot(xdata, ydata)
  38.         line['x'].append(line['x'][-1] + updateInterval)
  39.         line['y'].append(con)
  40.  
  41.     plot(*[line['x'], line['y'] for line in graphData])
  42.  
Nov 22 '07 #1
2 2184
bartonc
6,596 Recognized Expert Expert
As much as I dislike globals, working on the module level like this, it is convenient:
Expand|Select|Wrap|Line Numbers
  1. updateInterval = 0
  2.  
  3. def initGraph(interval, *colours):
  4.     """Initializes this module
  5.  
  6.     interval: the time, in seconds, btwn calls to updateGraph()
  7.     colours: list of 3-tuples (r,g,b) for each line's colour
  8.     """
  9.     global updateInterval
  10.     updateInterval = interval
  11.     for c in colours:
  12.         line = plot([0],[0])[0]
  13.         line.set_color(c)
  14.         graphData.append({'x':[0],'y':[0]})
  15.         #graphLines.append(line)
Otherwise, updateInterval remains a function-scope variable and nobody else sees the change.

That's the first thing that caught my eye... I'll keep looking.
Nov 22 '07 #2
sydneytroz
7 New Member
thanks, i appreciate your help
Nov 26 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

0
2018
by: Constandinos Mavromoustakis | last post by:
Dear all, first we apologize if you receive multiple copies of this announcement. please see below if you are interested. Thank you in advance. ============================================================================ =
0
2384
by: Constandinos Mavromoustakis | last post by:
http://agent.csd.auth.gr/~cmavrom -------------------------------------------------- ============================================================================ = 37th Annual Simulation Symposium April 18 - 22, 2004 Hyatt Regency Crystal City
0
2008
by: Gus | last post by:
---------------------------------------------------------------------------- ------------------------------------ Call for Papers: 38th Annual Simulation Symposium Part of the 2005 Spring Simulation Multiconference San Diego, April 2-8, 2005 Hilton Mission Valley Hotel
0
1780
by: Karatza Helen | last post by:
Our apologies if you have received multiple copies -------------------------------------------------- Call for Papers: 38th Annual Simulation Symposium Part of the 2005 Spring Simulation Multiconference San Diego, April 2-8, 2005 Hilton Mission Valley Hotel
1
1694
by: fRzzy madayaz | last post by:
Hello, I'm new to this kind of applications. Can you give me the concept of making a real-time interactive application. Let's say, it's like MSN Messenger or Yahoo! Messenger, where several clients can interact with each other in real-time.
1
2973
by: robby.walker | last post by:
Hi, I've just released a full-featured online graphing calculator at http://www.e-tutor.com/et2/graphing/ It requires no downloads or plugins - just JavaScript. You can track points on the curve, graph multiple functions, and more. A lot of this functionality is implemented in JavaScript. I'm very interested in hearing people's feature requests.
3
976
by: informat | last post by:
Hi : I have a very difficulty question ... I want to program a Simulation for a windows interactive exam .. if someone watched a Testout MCSE Class , he would see an Exam which a Windows Simulator asks him to add a user , or disable one ..... this exam records what you do and display the score .. I want to develop a simulator like that ... can anyone help me with an idea how to make it ?? thanks all ...
0
1351
by: Dexter | last post by:
GraphEasyRect was previously available as an applet. Now we have converted it to a desktop standalone application that runs on multiple platforms Windows, Mac, and Linux This tool allows graphing functions in cartesian plane, points of discontinuity having limits are encircled on graph line. You may view and copy the values of the function between a range of x values
1
1785
by: skeates | last post by:
Hey all - I'm attempting to write a program that accesses a database, runs some calculations according to user input, and then creates some graphs from the results. The first two steps were pretty simple, but I was disappointed to discover that VB.NET (at least the express edition) doesn't have any sort of built in graphing controls. My original thought is that one could snag the class library from excel and create one's own chart object on a...
0
8921
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8763
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9284
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9202
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8151
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6722
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4528
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4796
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3238
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.