I'm just getting started with Gnuplot and would like to plot data from a CSV file of the form:

A, B, C, D, E
25,1,106.951,102.334,9.73
25,2,99.264,94.728,2.124
...
25,55,94.979,94.574,1.97
25,56,95.083,94.759,2.155
20,1,103.531,98.914,6.959
20,2,97.370,92.834,0.879
...
20,54,100.091,99.605,7.65
20,56,116.399,115.994,24.039
21,1,104.673,100.056,8.281
21,2,97.045,92.509,0.734
...

I can read in and plot required columns from specified number of rows, okay, e.g. using something of the form:

gnuplot> set term x11
//My mac doesn't display anything with the aqua setting?
gnuplot> set datafile separator "," 
//my data file is CSV, so define the separator, just in case...
gnuplot>  plot 'myyFile.csv' every::1::56  using 2:5 with lines
// every::1::56 says use rows 1 to 56 inclusive (skipping header row 0)
// using 2:5 says use cols 2 and 5 (where the first col is col 1)

What I want to do is plot cols 2 and 5 ( using 1:5) for rows where the value in column 1 is specificed (so I need some way of saying "where col1val==3"). Is there a way of doing this within gnuplot?

asked 09 May '11, 18:25

psychemedia's gravatar image

psychemedia ♦♦
1.1k323961
accept rate: 11%

edited 09 May '11, 18:43


To answer my own question, http://lavica.fesb.hr/cgi-bin/info2html?(gnuplot)using suggests the following solution

One trick is to use the ternary ?: operator to filter data: plot 'file' using 1:($3>10 ? $2 : 1/0) which plots the datum in column two against that in column one provided the datum in column three exceeds ten. 1/0 is undefined; gnuplot quietly ignores undefined points, so unsuitable points are suppressed.are suppressed.

So for my example, plot 'myyFile.csv' using ($1==3 ? $2:1/0):5 with lines seems to do the trick...

link

answered 09 May '11, 18:43

psychemedia's gravatar image

psychemedia ♦♦
1.1k323961
accept rate: 11%

edited 09 May '11, 18:46

It's a few years since I've used gnuplot in anger, but if you know a simple way to filter the data outside gnuplot (using grep, for example) then I'm fairly sure you can convince gnuplot to read data from a pipe rather than a file and achieve similar - or more complex - effects. Something like plot "|grep '^1,' < myfile.csv" ...

link

answered 03 Jun '11, 15:10

cziwkga's gravatar image

cziwkga
162
accept rate: 0%

Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Tags:

×4
×2

Asked: 09 May '11, 18:25

Seen: 8,029 times

Last updated: 03 Jun '11, 15:10

powered by OSQA