From: Michael H. <mh...@ka...> - 2004-11-06 02:31:39
|
kevin parks wrote: > I have data that looks like: > > 0 5.5 0 1 > 2 5.5 2 4 > 4 5.5 4 2 > 6 5.5 5 3 > 8 5.5 7 1 > 10 5.5 9 4 > 12 5.5 11 3 > 14 5.5 0 2 > 16 5.5 2 1 > 18 5.5 4 4 > 20 5.5 5 3 It's easiest if you put your data into a file in the above format, rather than typing it into Python as a list constant. > [...] I would like to use splot and points of different colors to > convey as much info as i can. The X axis would be the time axis (that > would take care of the first two parameters) and the Y axis could be > the third column. Then for the fouth item, there are only four > possibilities (1, 2, 3, or 4), so i thought that i could use points of > red, blue, green, black to indicate that. I don't believe gnuplot offers a way to vary the style of points depending on a data column, so I believe you should read the data into Python, then use Python to pick it apart into four separate data sets, then plot the four sets in one plot using four different data styles. I believe the following script should do the trick. It uses some newer python features (2.2?) so parts might have to be changed if you are using an older version of python. Run it with the name of your data file as command-line argument. |#! /usr/bin/env python import sys import Numeric import Gnuplot [filename] = sys.argv[1:] data = [] for l in open(filename).readlines(): l = l.strip().split() data.append([float(l[0]), float(l[1]), float(l[2]), int(l[3])]) values = [1,2,3,4] # Here you can adjust the style options for each subset. The # interpretation of the numbers depends on what "terminal" you are # using. styles = { 1 : 'points pt 1', 2 : 'points pt 2', 3 : 'points pt 3', 4 : 'points pt 4', } subsets = {} for value in values: subsets[value] = [l for l in data if l[3] == value] g = Gnuplot.Gnuplot() items = [ Gnuplot.Data( subsets[value], with=styles[value], using=(1,3,), ) for value in values ] g.plot(*items) raw_input('Press enter to continue') Yours, Michael | -- Michael Haggerty mh...@al... |