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

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 ♦♦
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...


answered 09 May '11, 18:43

psychemedia's gravatar image

psychemedia ♦♦
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" ...


answered 03 Jun '11, 15:10

cziwkga's gravatar image

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



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



Asked: 09 May '11, 18:25

Seen: 8,029 times

Last updated: 03 Jun '11, 15:10

powered by OSQA