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 2184 bartonc 6,596
Recognized Expert Expert
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 Symposium
April 18 - 22, 2004
Hyatt Regency Crystal City
|
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
|
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
|
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.
| |
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.
|
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 ...
|
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
|
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...
|
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...
|
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,...
| |
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...
|
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,...
|
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...
|
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...
|
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...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
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
| |