0

I'm trying to plot some data from a file which contains a timestamp and comments as a string and various other data.

What's woking so far is to plot all comments as label with the time, but I'm looking for some kind of intelligent spacing, so that the comments don't overlap.

I'm also looking for a way to filter the comments. I got another column which specifies if the comment is supposed to be hidden or not. I'm using this Statment for conditional plotting:

plot 'data' using $1:0:($7==0?$6:" ")

It's filtering the datapoints but instead of showing the string in ($6) it's showing 0 if the Statment is true.

I think I can work around the spacing by manipulating the time by hand if the distance is too small, but a working filter would be a great help.

Has anyone dealt with this kind of problem before? I added a picture below of my progress so far.

I appreciate any suggestions. Thank you.

Plot

Community
  • 1
  • 1
A. Klose
  • 5
  • 3

2 Answers2

0

In order to make your labels not overlap, what about rotating them down and out of the way with rotate by -60?

The default bottom margin would cut them off, in which case you'd need to expand it with something like set bmargin 10.

To plot conditionally, you need to generate a numerical error, not just a zero value, when the condition is false. The simplest way might be:

plot 'data' using $1:0:($7==0?$6:NaN)

although in older scripts one often sees 1/0 used to generate the NaN, as in:

plot 'data' using $1:0:($7==0?$6:1/0)

Instead of conditional plotting, you could set explicit labels, as in:

set xdata time
set timefmt "%d/%m/%y\t%H%M"
set format x "%d/%m\n%H:%M"
set xrange [ "1/6/93":"1/11/93" ]
set grid
set style data fsteps
set bmargin 10
set label 1 'Look at the spike here' at '01/10/93',0.05 rotate by -45 point
# https://github.com/gnuplot/gnuplot/blob/master/demo/timedat.dat
plot 'timedat.dat' using 1:4 notitle

That produces resulting plot

MassPikeMike
  • 672
  • 3
  • 12
  • Somehow gnuplot doesn't like the string output in combination with the conditional plotting. Using explicit labels is a good alternative, but the amount of comments is probably still gonna rise.Thank you for your response – A. Klose Apr 27 '17 at 12:57
0

To use text fields inside a using expression one must use the stringcolumn function. For your example, something like

plot 'data' using $1:(0):($7==0 ? stringcolumn(6) : " ") with labels

should work for the filtering aspect of your question.

user8153
  • 4,049
  • 1
  • 9
  • 18
  • Works perfectly! With the conditional label plotting the spacing isn't that important anymore since the amount of comments is drastically reduced. Thanks a lot for your help! – A. Klose Apr 29 '17 at 13:39