Sophie

Sophie

distrib > Mandriva > 8.2 > i586 > media > contrib > by-pkgid > 8b2b1fb157760a0d31e072e140388824 > files > 183

gri-2.8.0-1mdk.i586.rpm

<html>
<head>
<title>Gri: xy plots</title>
</head>
<body bgcolor="#FFFFFF" text="#000000" link="#0000EE" vlink="#551A8B" alink="FF0000">
<!-- newfile X-Y.html "Gri: xy plots" "X-Y Plots" --> 

<!-- @node   X-y Plots, Linegraphs, Pen Color, Top -->
<a name="X-yPlots" ></a>

<img src="./resources/top_banner.gif" usemap="#navigate_top" border="0">
<table summary="top banner" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="150" valign="top">
<font size=-1>
<br>
Chapters:
</br>
&nbsp;&nbsp;<a href="Introduction.html">1: Introduction</a><br>
&nbsp;&nbsp;<a href="SimpleExample.html">2: Simple example</a><br>
&nbsp;&nbsp;<a href="InvokingGri.html">3: Invocation</a><br>
&nbsp;&nbsp;<a href="GettingMoreControl.html">4: Finer Control</a><br>
&nbsp;&nbsp;<a href="X-Y.html">5: X-Y Plots</a><br>
&nbsp;&nbsp;<a href="ContourPlots.html">6: Contour Plots</a><br>
&nbsp;&nbsp;<a href="Images.html">7: Image Plots</a><br>
&nbsp;&nbsp;<a href="Examples.html">8: Examples</a><br>
&nbsp;&nbsp;<a href="Commands.html">9: Gri Commands</a><br>
&nbsp;&nbsp;<a href="Programming.html">10: Programming</a><br>
&nbsp;&nbsp;<a href="Environment.html">11: Environment</a><br>
&nbsp;&nbsp;<a href="Emacs.html">12: Emacs Mode</a><br>
&nbsp;&nbsp;<a href="History.html">13: History</a><br>
&nbsp;&nbsp;<a href="Installation.html">14: Installation</a><br>
&nbsp;&nbsp;<a href="Bugs.html">15: Gri Bugs</a><br>
&nbsp;&nbsp;<a href="TestSuite.html">16: Test Suite</a><br>
&nbsp;&nbsp;<a href="Acknowledgments.html">17: Acknowledgments</a><br>
&nbsp;&nbsp;<a href="License.html">18: License</a><br>
<br>
Indices:</br>
&nbsp;&nbsp;<a href="ConceptIndex.html"><i>Concepts</i></a><br>
&nbsp;&nbsp;<a href="CommandIndex.html"><i>Commands</i></a><br>
&nbsp;&nbsp;<a href="BuiltinIndex.html"><i>Variables</i></a><br>
</font>
<td width="500" valign="top">
<map name="navigate_top">
<area alt="index.html#Top" shape="rect" coords="5,2,218,24" href="index.html#Top">
<area alt="index.html#Top" shape="rect" coords="516,2,532,24" href="index.html#Top">
<area alt="Gri: pen color" shape="rect" coords="557,2,573,24" href="PenColor.html">
<area alt="Gri: contour plots" shape="rect" coords="581,2,599,24" href="ContourPlots.html">
</map>
<map name="navigate_bottom">
<area alt="index.html#Top" shape="rect" coords="5,2,218,24" href="index.html#Top">
<area alt="Gri: contour plots" shape="rect" coords="581,2,599,24" href="ContourPlots.html"></map>
<h1>5: X-Y Plots</h1>


<UL>
<LI><a href="X-Y.html#Linegraphs">Linegraphs</a>: x-y graphs with data connected by line segments
<LI><a href="X-Y.html#Scattergraphs">Scattergraphs</a>: x-y graphs with data indicated by symbols
<LI><a href="X-Y.html#FormulaPlots">Formula Plots</a>: 
</UL>

<!-- @node   Linegraphs, Scattergraphs, X-y Plots, X-y Plots     -->
<a name="Linegraphs" ></a>
<h2>5.1: Linegraphs</h2>

The following Gri commands will draw a linegraph.  For the output graph
(see <a href="GettingMoreControl.html#GettingMoreControl">Getting More Control</a>).
<p>
This plots a simple linegraph:
<p>
<A HREF="example1.png"> 
<IMG ALT="Example 1" SRC="example1-tiny.png" 
ALIGN=top> 
</A> 


<TABLE SUMMARY="Example" BORDER="0" BGCOLOR="#efefef" WIDTH="100%">
<TR>
<TD>
<PRE>
<font color="#82140F">
# Example 1 -- Linegraph using data in a separate file
<p>
open example1.dat      # Open the data file
read columns x y       # Read (x,y) columns
draw curve             # Draw data curve
draw title "Example 1" # Title above plot
</font></PRE>
</TD>
</TR>
</TABLE>
<p>
Here's what the command lines mean:
<p>
<ul>
<li>
The first line is a comment.  Anything to the right of a hash-mark
`<font color="#82140F"><code>#</code></font>' is considered to be a comment.  (This symbol is also called a
"pound".)
<p>
<li>
The second line is blank.  Gri ignores blank lines between commands.
<li>
`<font color="#82140F"><code>open example1.dat</code></font>' tells Gri to open the indicated file (in
the current directory) as an input data file.  You can specify files
outside the current directory by using conventional unix-shell pathnames
(e.g., `<font color="#82140F"><code>open ~/data/TS/section1/T_S.dat</code></font>' or 
`<font color="82140F"><code>open ../data/file.dat</code></font>').  You can even use "synonyms" (see <a href="Synonyms.html#Synonyms">Synonyms</a>.) in
filenames, as in `<font color="#82140F"><code>open \BASENAME.dat</code></font>'.
<li>
`<font color="#82140F"><code>read columns x y</code></font>' tells Gri to start reading columnar data,
the first column being `<font color="#82140F"><code>x</code></font>', the second `<font color="#82140F"><code>y</code></font>'.  `<font color="#82140F"><code>x</code></font>' and
`<font color="#82140F"><code>y</code></font>' are predefined names for whatever ends up on the horizontal and
vertical axes.  
<p>

The number of data needn't be specified.  Gri reads columns until a
blank line or end-of-file is found.  You can tell Gri how many lines to
read with a command like `<font color="#82140F"><code>read columns 10 x y</code></font>'.  Multiple datasets
can reside within one file; provided that they are separated by a single
blank line, Gri can access them by multiple `<font color="#82140F"><code>read</code></font>' commands.
<p>
Like C, Gri expects numbers to be separated by one or more spaces or
tabs.  Commas are not allowed.  If the columns were reversed, the
command would be `<font color="#82140F"><code>read columns y x</code></font>'.  If there were an initial
column of extraneous data, the command would be 
`<font color="#82140F"><code>read columns * x y</code></font>', or `<font color="#82140F"><code>read columns x=2 y=3</code></font>'
(see <a href="Read.html#ReadColumns">Read Columns</a>).
<li>
`<font color="#82140F"><code>draw curve</code></font>' tells Gri to draw a curve connecting the points
in the `<font color="#82140F"><code>x</code></font>' and `<font color="#82140F"><code>y</code></font>' columns. A nice scale will be selected
automatically.  (You can change this or any other plot characteristics
easily, as you'll see later.)
<li>
`<font color="#82140F"><code>draw title</code></font>' tells Gri to write the indicated string
centered above the plot. The title <b>must</b> be enclosed in quotes.
<li>
`<font color="#82140F"><code>quit</code></font>' tells Gri to exit.
</ul>
<p>
Gri will draw axes automatically, and pick its own scales.
<p>
If you wish to draw several curves which cross each other, you should
try using `<font color="#82140F"><code>draw curve overlying</code></font>' instead of
`<font color="#82140F"><code>draw curve</code></font>'.  This will make it easier to distinguish the
different curves.
<p>

<!-- @node   Scattergraphs, Formula Plots, Linegraphs, X-y Plots -->
<a name="Scattergraphs" ></a>
<h2>5.2: Scattergraphs</h2>

This section contains two examples, the first being a fuller explanation
of all the bells and whistles, the second being a simple explanation
of how to get a very quick plot, given just a file containing a matrix
of grid data.
<p>

To get a scattergraph with symbols at the data points, substitute
`<font color="#82140F"><code>draw symbol</code></font>' for `<font color="#82140F"><code>draw curve</code></font>'.  Both symbols and a curve
result if both `<font color="#82140F"><code>draw curve</code></font>' and `<font color="#82140F"><code>draw symbols</code></font>' are used.
See see <a href="GettingMoreControl.html#GettingMoreControl">Getting More Control</a> for an example.
<p>

By default, the symbol used is an x.  To get another symbol, use a
command like `<font color="#82140F"><code>draw symbol 0</code></font>' or `<font color="#82140F"><code>draw symbol plus</code></font>'.  These are
the numerical codes and the associated names:
<p>
<TABLE SUMMARY="Example" BORDER="0" BGCOLOR="#efefef" WIDTH="100%">
<TR>
<TD>
<PRE>
<font color="#82140F">
0  plus         
1  times        
2  box          
3  circ         
4  diamond      
5  triangleup   
6  triangleright
7  triangledown 
8  triangleleft 
9  asterisk     
10 star         
11 filledbox    
12 bullet       
13 filleddiamond
14 filledtriangleup
15 filledtriangleright 
16 filledtriangledown 
17 filledtriangleleft
</font></PRE>
</TD>
</TR>
</TABLE>
<p>
To change the symbol size from the default of 0.2 cm use commands like
`<font color="82140F"><code>set symbol size 0.1</code></font>' to set to 1 mm (see <a href="Set.html#SetSymbolSize">Set Symbol Size</a>).
<p>
<h3>5.2.1: Coding data with symbols</h3>
To get different symbols for different data points, insert symbol codes
from the above list as a column along with the x-y data, and substitute
the command `<font color="#82140F"><code>read columns x y z</code></font>', and then draw them with
`<font color="#82140F"><code>draw symbol</code></font>'.  Gri will interpret the rounded-integer
values of the `<font color="#82140F"><code>z</code></font>' columns as symbol codes.  Note that even if
you've read in a z column which you intend to represent symbols, it will
be overridden if you designate a specific symbol in your 
`<font color="#82140F"><code>draw symbols</code></font>' command; thus `<font color="#82140F"><code>draw symbol 0</code></font>' puts a `<font color="#82140F"><code>+</code></font>'
at the data points whether or not you've read in a symbol column.
<p>
<h3>5.2.2: Drawing a symbol legend</h3>

The following example shows how you might write a symbol legend for a
plot.  The legend is drawn 1 cm to the right of the right-hand side of
the axes, with the bottom of the legend one quarter of the way up the
plot; see <a href="Draw.html#DrawSymbolLegend">Draw Symbol Legend</a>.  The lines in the legend are
double-spaced vertically.  To change the location of the legend, alter
the `<font color="#82140F"><code>.legend_x. =</code></font>' and `<font color="#82140F"><code>.legend_y. =</code></font>' lines.  To change the
spacing, alter the `<font color="#82140F"><code>.legend_y. +=</code></font>' line.
<p>
<TABLE SUMMARY="Example" BORDER="0" BGCOLOR="#efefef" WIDTH="100%">
<TR>
<TD>
<PRE>
<font color="#82140F">
set x axis -1 5 1
set y axis -1 5 1
read columns x y z
0 0 0
1 1 1
2 2 2
3 3 3
<p>
draw symbol
<p>
# Legend
.leg_x. = {rpn ..xmargin.. ..xsize.. + 1 +}
.leg_y. = {rpn ..ymargin.. ..ysize.. 4 / +}
draw symbol legend 0 "Foo" at .leg_x. .leg_y. cm
.leg_y. += {rpn ascent("M") 2 *}
draw symbol legend 1 "Bar" at .leg_x. .leg_y. cm
.leg_y. += {rpn ascent("M") 2 *}
</font></PRE>
</TD>
</TR>
</TABLE>
<p>

<h3>5.2.3: Coding data with symbol colors</h3>
To get different colors for different symbols, read a color code into
the z column, and do for example `<font color="#82140F"><code>draw symbol bullet color hue z</code></font>'.
The numerical color code ranges from 0 (red) through to 1, passing
through green at 1/3 and blue at 2/3.
<p>
<!-- @node   Formula Plots, Contour Plots, Scattergraphs, X-y Plots -->
<a name="FormulaPlots" ></a>
<h2>5.3: Formula Plots</h2>

There are two methods for formula graphs.
<p>
<ol>
<li> <b>Use the system yourself.</b>
Do as in this example:
<p>
<TABLE SUMMARY="Example" BORDER="0" BGCOLOR="#efefef" WIDTH="100%">
<TR>
<TD>
<PRE>
<font color="#82140F">
open "awk 'BEGIN{for(i=0;i&lt;3.141;i+=0.05)\
    {print(i,cos(i))}}' |"
read columns x y
close
draw curve
</font></PRE>
</TD>
</TR>
</TABLE>
<p>


<li> <b>Let Gri calculate things for you</b>
<p>
The simplest is to let Gri
calculate things for you with the `<font color="#82140F"><code>create columns from function</code></font>'
command (see <a href="Create.html#Create">Create</a>).  The command assumes that you have defined
the synonym called `<font color="#82140F"><code>\function</code></font>' which defines `<font color="#82140F"><code>y</code></font>' in terms of
`<font color="#82140F"><code>x</code></font>'.
<p>
Gri uses the program `<font color="#82140F"><code>awk</code></font>' to create the columns, and cannot work
without it.  
<p>
Here is an example of using `<font color="#82140F"><code>create columns from function</code></font>':
<p>
<TABLE SUMMARY="Example" BORDER="0" BGCOLOR="#efefef" WIDTH="100%">
<TR>
<TD>
<PRE>
<font color="#82140F">
show "First 2 terms of perturbation expansion"
set y axis label horizontal
set y name "sea-level"
set x name "$\omega$t"
<p>
\b = "0.4" # perturbation parameter b=dH/H
\xmin = "0"
\xmax = "6.28"
\xinc = "3.14 / 20"
\function = "cos(x)"
set x axis \xmin \xmax
create columns from function
draw curve
draw title "SOLID LINE  \function"
<p>
\function = "(cos(x)+\b/2*(1-cos(2*x)))"
create columns from function
set dash 1
draw curve
draw title "DASHED LINE \function"
<p>
draw title "b = \b"
</font></PRE>
</TD>
</TR>
</TABLE>
<p>
Here's another example, in which the curve `<font color="#82140F"><code>y = 1/(\int + \sl*x)</code></font>'
is drawn through some data.  Note how `<font color="#82140F"><code>sprintf</code></font>' is used to set
`<font color="#82140F"><code>\xmin</code></font>' and `<font color="#82140F"><code>\xmax</code></font>' using the scales that Gri has determined
in reading the data.
<p>
<TABLE SUMMARY="Example" BORDER="0" BGCOLOR="#efefef" WIDTH="100%">
<TR>
<TD>
<PRE>
<font color="#82140F">
open file.data
read columns x y
close
draw symbol bullet
\int = "-0.1235"
\sl = "0.003685"
sprintf \xmin "%f" ..xleft..
sprintf \xmax "%f" ..xright..
\function = "1/(\int + x * \sl)"
create columns from function
draw curve
</font></PRE>
</TD>
</TR>
</TABLE>
<p>
</ol>
<p>



</table>
<img src="./resources/bottom_banner.gif" usemap="#navigate_bottom" border="0">

</body>
</html>