next up previous
Next: Software Architecture Up: Graphite A portable graphing Previous: Graphite Goals and Status

Examples

The general schema for creating graphs is as follows:

1.
create a Graph
2.
attach one or more Datasets
3.
attach or configure one or more PlotFormats
4.
add any overlays (extra labels, arrows, etc.)
5.
call the Graph's draw() method
By using utility functions it is possible to create a graph very easily. The below example (1) creates a graph, (2) attaches a dataset which was stored in a file, and (5) calls the Graph g's draw method by using the utility function genOutput. The resulting graph is shown in figure 1. Notice that steps (3) and (4) above are optional because a default PointPlot format is used automatically, and because overlays are not necessary.
 
Figure 1:  First attempt at graphing a Point Plot
\begin{figure*}
{\par\centering 
\resizebox 
*{0.8\textwidth}{!}{
\includegraphics {karin1.eps}
} \par}
\end{figure*}

    from graphite import *
    g = Graph() 
    data = loadTable('karin.dat',' ') 
    g.datasets.append(Dataset(data)) 
    genOutput(g,'PS')

After creating the very simple graph it is then possibe to export all of this graph's settings in a string. If this string is written to a file, we can then change all the properties of the graph. All of the graph properties can be printed to a file using the following code.

f = open('settings.py','w')
f.write(g.exportString('g'))
f.close()

That file can them be edited to make any changes to the graph which are desired. Below are some example properties as generated from exportString.

# list of PlotFormat objects which will be used in a round-robin fashion by the Datasets
g.formats = [PointPlot()]

# style used to draw the lines, or None if no lines are desired
g.formats[0].lineStyle = LineStyle(width=1, 
	color=Color(0.00,0.00,0.00), kind=SOLID)

By making the changes to various properties listed in the settings file and then executing the edited file, we were able to change figure 1 to figure 2.

f = open('settings.py')
commands = f.readlines()
f.close()
import string
commands = string.join(commands,'')
exec(commands)
genOutput(g,'PS',size=(400,250))


 
Figure 2:  After editing the graph properties
\begin{figure}
{\par\centering 
\resizebox 
*{0.8\textwidth}{!}{
\includegraphics {karin2.eps}
} \par}
\end{figure}

Figure 3 and figure 4 show two more examples of graphs which can be generated with Graphite.


 
Figure 3:  Bar chart example
\begin{figure}
{\par\centering 
\resizebox 
*{0.8\textwidth}{!}{
\includegraphics {bargraph.eps}
} \par}
\end{figure}


 
Figure 4:  3D Point plot example
\begin{figure}
{\par\centering 
\resizebox 
*{0.8\textwidth}{!}{
\includegraphics {spiral.eps}
} \par}
\end{figure}


next up previous
Next: Software Architecture Up: Graphite A portable graphing Previous: Graphite Goals and Status
Michelle Mills Strout
11/15/1999