Linecolor (not so) variable - colors

I'm trying to present data in a boxplot with a few additions.
On top of the boxplot, i want to also print all the data points, since there aren't that many.
There will be many boxplots side by side, and the data points will correspond, so each data point in one plot will be represented in another boxplot, however their order can change. That's why I want to color the points.
I got this so far:
plot data using (1):($1) with boxplot,\
data using (1):($1) with points lc variable
[more plots...]
This needs an extra column in each datafile, that specifies the linecolor. Which works fine, if I had such a column, or if I could care to add it.
Is there another way to iterate through the linestyles (or colors), so it plots the first point with style 1, the second with style 2 etc.?
It seems like a real easy problem, that's either solved by some command I can't seem to find, or maybe by taking the linestyles from a different file, which would be the same for all plots (if that works in gnuplot).
Furthermore, I'd like to know if the boxplot command has the additional feature of being able to plot the average as well (or do I absolutely need the stats command from gnuplot 4.6, or some kind of hack).
Sometimes it's just nice to be able to simply add the average in a boxplot.

Is there another way to iterate through the linestyles (or colors), so it plots the first point with style 1, the second with style 2 etc.?
Yes. Gnuplot provides a number of pseudo-columns. To get more information, see
help datafile using pseudocolumn
But the gist of it is that you can use column(0) for this. I believe that iteration starts at 0 though. Since there isn't a ls 0, you'll need to add 1.
plot data using (1):($1) with boxplot,\
data using (1):($1):(column(0)+1) with points lc variable
Furthermore, I'd like to know if the boxplot command has the additional feature of being able to plot the average as well (or do I absolutely need the stats command from gnuplot 4.6, or some kind of hack).
I believe that you need either gnuplot 4.6 or some kind of hack. One such hack (which will work using gnuplot 4.4, but not earlier) could be:
sum=0.0
npt=0
compute_sum_npt(x)=(npt=npt+1,sum=sum+x,NaN)
set term unknown
plot data u 1:(compute_sum_npt($1))
avg=sum/npt
set term ...
set output ...
plot data using (1):($1) with boxplot,\
data using (1):($1):(column(0)+1) with points lc variable,\
avg w lines ls -1
If your version of gnuplot is earlier than 4.4, you'll need to use a shell command to compute the average. Something like awk should suffice.

Related

Better understanding histograms in Gnuplot

In gnuplot, you can create a histogram like
binwidth=#whatever#
set boxwidth binwidth
bin(x,width)=width*round(x/width)
plot "gaussian.data" u (bin($1,binwidth)):(1.0/10000) smooth freq w boxes
Here, I am interested in a probability histogram, hence the 1.0/10000.
I have spend a lot of time reading the gnuplot documentation on using and what I understand is that I am telling gnuplot to plot data from gaussian.data using certain values for the x and y. In fact, when I open the data file associated with the plot command (achieved through making a temporary file), I see that the y values are 1/10000, as expected. But then, the x and y values change. It seems like there's something dynamic about it. I do not quite understand this behavior of using. Could anyone please guide me?
In case anyone else would like further explanation.
http://psy.swansea.ac.uk/staff/carter/gnuplot/gnuplot_frequency.htm

Exchanging the axes in gnuplot

I have been wondering about this for a while, and it might already be implemented in gnuplot but I haven't been able to find info online.
When you have a data file, it is possible to exchange the axes and assign the "dummy variable", say x, (in gnuplot's help terminology) to the vertical axis:
plot "data" u 1:2 # x goes to horizontal axis, standard
plot "data" u 2:1 # x goes to vertical axis, exchanged axes
However, when you have a function, you need to resort to a parametric function to do this. Imagine you want to plot x = y² (as opposite to y = x²), then (as far as I know) you need to do:
set parametric
plot t**2,t
which works nicely in this case. I think however that a more flexible approach would be desirable, something like
plot x**2 axes y1x1 # this doesn't work!
Is something like the above implemented, or is there an easy way to use y as dummy variable without the need to set parametric?
So here is another ugly, but gnuplot-only variant: Use the special filename '+' to generate a dynamic data set for plotting:
plot '+' using ($1**2):1
The development version contains a new feature, which allows you to use dummy variables instead of column numbers for plotting with '+':
plot sample [y=-10:10] '+' using (y**2):(y)
I guess that's what come closest to your request.
From what I have seen, parametric plots are pretty common in order to achieve your needs.
If you really hate parametric plots and you have no fear for a VERY ugly solutions, I can give you my method...
My trick is to use a data file filled with a sequence of numbers. To fit your example, let's make a file sq with a sequence of reals from -10 to 10 :
seq -10 .5 10 > sq
And then you can do the magic you want using gnuplot :
plot 'sq' u ($1**2):($1)
And if you uses linux you can also put the command directly in the command line :
plot '< seq -10 .5 10' u ($1**2):($1)
I want to add that I'm not proud of this solution and I'd love the "axis y1x1" functionality too.
As far as I know there is no way to simply invert or exchange the axes in gnuplot when plotting a function.
The reason comes from the way functions are plotted in the normal plotting mode. There is a set of points at even intervals along the x axis which are sampled (frequency set by set samples) and the function value computed. This only allows for well-behaved functions; one y-value per x-value.

gnuplot: filling the whole space when plotting sampled data

I have a problem with gnuplot. I've searched and I don't find the correct solution. I'm plotting some data arranged in three columns with the command splot, and the steps in x and y are different. The plot I get with:
set view map
splot 'data.dat' using 1:2:3 with points palette
is:
and I would like the white space to be filled, making each tile size adapt, avoiding interpolation.
Some ideas are given here Reduce distance between points in splot.
I've tryed http://gnuplot.sourceforge.net/demo/heatmaps.html too, but with image doesn't seem to work :(
I should avoid pointsize as my grid changes from time to time.
You can try
set pm3d map interpolate 1,1 corners2color c1
splot 'data.dat' using 1:($2-5e-5):3
This uses no interpolation, and the color of each polygon depends on the value of corner 'c1'. You may need to test if this is the correct one, or if you need 'c2', 'c3', or 'c4'.
Another solution to my problem, better than this one for some terminals at least, is given in the answers to my other question about maps appearance in pdfcairo terminal, where the solution comes when using plot with image insted of this splot. I tried to use that before, as I mention here, but maybe it also needed this specific data format.

How to plot this data into GNUplot

I have a program producing data like this:
0.5 0.5
0.49597550441921423 0.7868142593062702
0.5 0.5
0.6538646510750382 0.5364703734652149
an so on..
This is network topology data. I am told this is gnuplot friendly data however
I ask how to plot this data to gnuplot as it's is not a program I am
familiar with. Ideally the data should form star pattern clusters. Should also add
this data is in a .dat file however I worked it to a .txt for readability.
Thanks!
a simple:
plot 'yourdatafile' using 1:2
should plot something. However, actually customizing the plot to look exactly how you want it is the tricky part.

Using images for points in gnuplot

I have a frivolous question. Is there any way to use an image in lieu of points in gnuplot? For example, if I was plotting data about pasta consumption or something, I would have pictures of pasta (instead of usual gnuplot points).
Another option is to find a dingbats type of font with a suitable glyph. Then you can use "plot with labels" using that glyph as the label string. See for example the 5th plot in the demo
http://gnuplot.sourceforge.net/demo/stringvar.html
I haven't played around with this feature at all myself, however, there is:
http://gnuplot.sourceforge.net/demo/barchart_art.html
Which shows the use of png files on a bar chart (Note, that this feature was added in Gnuplot 4.5 -- I think). With a little creativity, it seems like you could use that feature to do what you're asking -- although it would require a whole bunch of plot commands so it might be useful to write a script to generate the gnuplot script (or use iteration depending on your dataset) -- Obviously your image files would have to be in a format that your version of gnuplot understands as well ...
A possible strategy may be the plot with rgbimage option in gnuplot.
See the second example over here: http://www.gnuplot.info/demo_4.2/image.html
If you relate the center option with your data points, this may be possible.

Resources