[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Q] drawing straight lines in a Graph-like window
From: |
Benedikt Stefansson |
Subject: |
Re: [Q] drawing straight lines in a Graph-like window |
Date: |
Tue, 06 Jul 1999 12:08:56 +0200 |
Norberto Eiji Nawa wrote:
>
> Hello:
>
> I have a set of (x, y) coordinates that I would like to display in a
> window that looks like a Graph window (i.e. labels in the x-y axes,
> labels for the scale, auto-scale in the y axis).
>
> The data is not a time series (demand and supply curves, actually), so
> I guess I will have to build everything using Canvas (and as a newbie,
> I am not exactly encouraged to do that). Does anyone have a better
> (easier) idea?
>
> Thanks a lot in advance,
>
> Eiji
>
> ==================================
> Swarm-Support is for discussion of the technical details of the day
> to day usage of Swarm. For list administration needs (esp.
> [un]subscribing), please send a message to <address@hidden>
> with "help" in the body of the message.
There is actually a FunctionGraph class which does pretty much exactly
what you want, however I think it can't handle two functions at the same
time:
http://www.santafe.edu/projects/swarm/swarmdocs/refbook/swarm.analysis.functiongraph.protocol.html
Here is another way to do the same, with an arbitrary number of
'functions'. You simply access Graph directly (EZGraph is a wrapper
around Graph and some other stuff. See also docs for Graph class).
Lets say you want to do a supply, demand curve graph.
Start by creating the graph (e.g. WIDTH=400 HEIGHT=300)
graph = [Graph createBegin: self];
graph = [graph createEnd];
[graph setTitle: "title"];
[graph setWidth: WIDTH Height: HEIGHT];
Now create the graph elements, the curves:
supply = [graph createElement];
[supply setLabel: "supply curve"];
demand = [graph createElement];
[demand setLabel: "demand curve"];
The rest I haven't actually tested, but this might be the way to draw
the
curves. For example
double x;
double beta=1.0;
double gamma=-1.0;
for(x=0.0;x<1.0;x+=0.1) {
[supply addX: x Y: beta*x];
[demand addX: x Y: gamma*x];
}
Finally display the graph:
[graph pack];
To see this type of code in action, download the the ExperIPD example on
this webpage and
have a look at ObserverSwarm.m:
http://www.sscnet.ucla.edu/99W/polisci209-1/
-Benedikt
---
Present coordinates:
Dep. of Economics, Univ. of Trento, Via Inama 1, 38100 Trento, ITALY
Off: +39 0461 882246/267875 Mob: +39 347 0415721 Fax: +39 0461 882222
==================================
Swarm-Support is for discussion of the technical details of the day
to day usage of Swarm. For list administration needs (esp.
[un]subscribing), please send a message to <address@hidden>
with "help" in the body of the message.