2
votes

I have the below data in gnuplot:

2012-09-18  0   2   12
2012-03-15  1   4   5
2012-12-18  24  8   11
2012-09-18  2   8   11
2012-03-15  16  5   5
2011-12-06  5   2   3
2012-12-18  3   12  8
2012-09-18  4   4   8
2012-03-29  11  6   2
2011-12-06  9   7   3
2012-12-18  6   7   8
2012-09-18  4   3   8
2012-02-09  27  2   1
2012-12-18  2   1   8
2012-09-18  6   14  8

1st column; x (date)

2nd column; y

3rd column; the point color

4th column; number of occurrences(the point is duplicated)

I need to write a gnuplot program which:

  1. Draws my (x,y) points.
  2. Gives each point a different color depending on the 3rd column value (maybe over 50 different colors).
  3. If the 4th column is greater than 0 then the point is duplicated and it must be drawn n times and give its x,y a random positing with a small margin. for example, (rand(x)-0.5,rand(y)-0.5).

Another question, what is the best and fastest way/tool to learn gnuplot?

1

1 Answers

2
votes

This is supposed to be an extension to my answer for your other question drawing duplicated points in gnuplot with small margin:

You need to have the first column interpreted as time data. For this you need

set xdata time
set timefmt '%Y-%m-%d'

In order to set the point color, it is best to define a palette and then use linecolor palette, which sets the point color based on its value in the palette.

So, using the explanations from drawing duplicated points in gnuplot with small margin the final script is:

reset
filename = 'data.dat'

stats filename using 4 nooutput

set xdata time
set timefmt '%Y-%m-%d'

set format x '%Y-%m'

rand_x(x) = x + 60*60*24*7 * (rand(0) - 0.5)
rand_y(y) = y + (rand(0) - 0.5)

plot for [i=0:int(STATS_max)-1] filename \
    using (rand_x(timecolumn(1))):(i < $4 ? rand_y($2) : 1/0):3 pointtype 7 linecolor palette notitle

Some other things you must have in mind are:

  1. The stats call must come before set xdata time, because the statistics don't work with time data.
  2. When calculating with time data in the using statement, one needs to use the timecolumn function (as opposed to column or $.. in generic cases). This gives the time as a timestamp (i.e. in seconds).
  3. For that reason you need two different random functions for x and y, because of the very different scalings. Here, I used a 'jitter' of one week (60*60*24*7 seconds) on the time axis.

The result with 4.6.4 is:

enter image description here

Some remarks to your question about learning gnuplot: Try to solve your questions by yourself and then post more concrete questions! Browse through the gnuplot demos to see what is possible, look which feature or plotting style is used, look them up in the documentation, what options/settings are offered? Play around with those demos and try to apply that to your data sets etc. In the end its all about practice (I've been using gnuplot for 12 years...).