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. -
from pylab import *
-
-
# Turn on interactive mode for graphing
-
ion()
-
#hold(False)
-
xlabel("time (seconds)")
-
ylabel("concentration (particles/window)")
-
-
#graphLines = []
-
graphData = []
-
updateInterval = 0
-
-
def initGraph(interval, *colours):
-
"""Initializes this module
-
-
interval: the time, in seconds, btwn calls to updateGraph()
-
colours: list of 3-tuples (r,g,b) for each line's colour
-
"""
-
updateInterval = interval
-
for c in colours:
-
line = plot([0],[0])[0]
-
line.set_color(c)
-
graphData.append({'x':[0],'y':[0]})
-
#graphLines.append(line)
-
-
def updateGraph(*cons):
-
"""Updates graph data and draws it
-
-
cons: a list of concentrations, the same length of colours arg to initGraph
-
"""
-
#for line, con in zip(graphLines, cons):
-
for line, con in zip(graphData, cons):
-
#xdata, ydata = line.get_xdata(), line.get_ydata()
-
#xdata.append(xdata[-1] + updateInterval)
-
#ydata.append(con)
-
#line.set_data(xdata, ydata)
-
#plot(xdata, ydata)
-
line['x'].append(line['x'][-1] + updateInterval)
-
line['y'].append(con)
-
-
plot(*[line['x'], line['y'] for line in graphData])
-
2 2173
As much as I dislike globals, working on the module level like this, it is convenient: -
updateInterval = 0
-
-
def initGraph(interval, *colours):
-
"""Initializes this module
-
-
interval: the time, in seconds, btwn calls to updateGraph()
-
colours: list of 3-tuples (r,g,b) for each line's colour
-
"""
-
global updateInterval
-
updateInterval = interval
-
for c in colours:
-
line = plot([0],[0])[0]
-
line.set_color(c)
-
graphData.append({'x':[0],'y':[0]})
-
#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.
thanks, i appreciate your help
Sign in to post your reply or Sign up for a free account.
Similar topics
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....
|
by: Constandinos Mavromoustakis |
last post by:
http://agent.csd.auth.gr/~cmavrom
--------------------------------------------------
============================================================================
=
37th Annual Simulation...
|
by: Gus |
last post by:
----------------------------------------------------------------------------
------------------------------------
Call for Papers: 38th Annual Simulation Symposium
Part of the 2005 Spring...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
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,...
|
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...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
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...
| |