Simple boxes graph using Gnuplot - gnuplot

I have a data file called for example dat.txt
0 3111 1755 2577 1895 3224 1725 2163 1641 2525 331
it's got a single line of data and for some reason i wanna plot them as vertical boxes for each value, rather than a line connecting all of the data points.
How can i do that with Gnuplot please, I think the version im stuck with for gnuplot is 4.2.6

What about help boxes or searching for boxes in the documentation? So, for boxes, use the boxes plotting style.
In any case, you must have your data organized in columns rather than as single row. On *nix you can do that on-the-fly with tr:
set style fill solid
set boxwidth 0.9
plot '< tr " " "\n" < dat.txt' with boxes
The output, with version 4.2.6 is:

Related

Annoying lines with style filledcurve

I am using gnuplot 5.0 patchlevel 3 and trying to plot a filledcurved generated from a data file. The data file is previously filtered and sorted with the help of awk and sort. A minimal script is
set style fill transparent solid 0.2
plot "<awk -f awkfile filename|sort -g -k 1" u 1:2 with filledcurve y1=90,'' u 1:2 w points
The output fills the curve up to y1=90, which is fine. However every data point is stick with a vertical line runnning from y to y1=90. The line is solid and non-transparent. It ruins the output. How can I get rid of them?

Plotting on Gnuplot - skipping lines

I have some problems with reading my file in Gnuplot.
For example, I have a file like this:
___________________________________________
'#current'
month followed retweeted mentioned replied
Jan 395 29 35 28
Feb 380 28 32 31
'#previous'
month followed retweeted mentioned replied
Jan 381 30 38 32
Feb 378 25 42 30
Mar 374 28 46 40
______________________________________________________
I need to read only the second block, which starts with tag "#previous". How can I do it? I tried this command:
plot "data.txt" index 'previous' using 3:xticlabel(1) axes x1y1 with lines linecolor rgbcolor "red",\
but it doesn't work. Any ideas?
Check out the answer to this question
Gnuplot: Plotting several datasets with titles from one file
I think you need to add a 1 after index like so
plot "data.txt" index 1 using 3:xticlabel(1) axes x1y1 with lines linecolor rgbcolor "red"
edit:
Datasets are 0-indexed so the first block is indexed 0 and the second block (previous) has an index one. The error you mention regarding the bad line indicates a problem with our data file format.
Read about the data format at these links
http://www.gnuplotting.org/plotting-data/
http://lowrank.net/gnuplot/datafile2-e.html
Let us put everything together:
Following this link you can learn how to filter the file (so you can get everything after certain line)
So in our case:
sed -e '1,/previous/d' data.txt > gnuplot some_gnuplot_options
I write this from my windows devel machine so can't validate but this should give you some idea how can you do this.
I would also recommend defining gnuplot config file you feed to gnuplot. Just create settings.pg and put there something like this (that's my example from some work I have done for myself so it does not apply to your data format):
set terminal png size 1024, 360
set output "load.png"
set datafile separator "\t"
set timefmt "%Y-%m-%d %H:%M:%S"
set xdata time
set format x "%m/%d\n%H:%M"
set xrange["2012-04-29 11:00:00":"2012-05-01 11:58:00"] noreverse nowriteback
set autoscale y
set grid
set key left box
plot "chart.txt" using 1:2 t 'column_1' with lines, "chart.txt" using 1:3 t 'column_2' with lines
So then your gnuplot call would look something like this:
sed -e '1,/previous/d' data.txt > gnuplot your_pg_file.pg
You would also want to check time formating from gnuplot manuals here.
edit:
If that's your university homework you should not post your question here :-) I don't want to be boring or something but is it not the goal of homework that you find your solution following documentation study and trying different things eh? :-)

Why doesn't the gnuplot grid extend over this whole plot?

Using gnuplot 4.6 patchlevel 1, with the following commands,
set grid linewidth 1 linecolor rgb"#888888"
set datafile separator ","
plot for [n=2:100] "data.csv" using 1:(column(n)) with lines linewidth 2
and the following example data in the file "data.csv",
time,S1,S2
0,0.00015,0
0.1,0.0001357256127053939,1.427438729460607e-005
0.2,0.0001228096129616973,2.719038703830272e-005
0.3,0.0001111227331022577,3.887726689774233e-005
0.4,0.0001005480069053459,4.945199309465411e-005
0.5,9.097959895689501e-005,5.902040104310499e-005
0.6,8.232174541410396e-005,6.767825458589604e-005
0.7,7.448779556871142e-005,7.551220443128858e-005
0.8,6.739934461758323e-005,8.260065538241677e-005
0.9,6.098544896108986e-005,8.901455103891014e-005
1,5.518191617571635e-005,9.481808382428365e-005
the resulting plot looks this:
Question: why does the grid only extend partway from the bottom, and not cover the whole plot? I tried a considerable amount of experimentation with the set xtics and ytics commands, arguments to grid, and more, and have not been able to get the grid to cover the whole plot. What am I missing?
Great question! In fact, the answer is that the grid does cover the whole plot. The problem is that the key is taking over. Try it again, but with an unset key in there before your plot command.
What's happening is that gnuplot is reserving space in the key for all of the columns which have no data. Nothing gets put in the space that was reserved since no reasonable data was found. Ultimately, this pushes the 2 lines that were visible out of the viewable canvas area as well.
I've reproduced this using the x11, png, postscript and pngcairo terminals.
Note that this behavior seems to be version dependent:
With gnuplot 4.4.2 (OS-X, png terminal)
With gnuplot 4.6.0 (OS-X, png terminal)
For those using gnuplot 4.4.4, perhaps there was a bug fix which made it work for gnuplot 4.4.4 and then a regression. It seems to persist into gnuplot 4.7.0 as well. I might file a bug report.

Gnuplot: line opacity / transparency?

I am using Gnuplot to successfully plot some time series data. However, the series are fairly dense (10,000's of samples in about 5 inches of space), and when I plot multiple series, it is hard to see underneath the series that was plotted on top. Is there any way to make the lines have a bit of opacity or transparency (i.e. make the line transparent so underneath lines are visible)?
Excel has this capability, but I would much prefer to use Gnuplot.
Below is a sample of what I'm talking about. You can't see the red lines under the green lines. I would actually like to add a third time series. I am plotting with the command:
plot [][-3:3] 'samples_all.csv' using 1:7 title 'horizontal' w l ls 1, '' using 1:8 title 'vertical' w l ls 2"
Good news! This has been implemented in gnuplot. Example syntax is
plot x lw 10, -x lw 10 lc rgb "#77000000"
This will plot x as a red line and -x as a transparent black line (it looks gray). The first pair of two characters in the rgb specification define the alpha (transparency) channel ("#AARRGGBB"). The normal syntax ("#RRGGBB") still works.
old (gnuplot < 5.0 or so) answer for reference:
If you want to make lines plotted for time series data, the answer is no (see discussion here). You can't set a line style to be transparent. Transparency only works for filling under curves, and it has to be printed to the right terminal type.
I ran into this problem myself recently, I hope this feature will be added in a future version of gnuplot.
This may be what you're looking for.

Plotting block data in 3d using different colors and smoothing the lines in Gnuplot or Octave

I am trying to plot (with Gnuplot) some basic 3d data from one file which is pretty much like that:
N M t1 t2 t3 t4
1000 1000 0.05268 0.04711 0.003947 0.003348
1000 2000 0.05743 0.04214 0.007577 0.006486
1000 3000 0.08465 0.04193 0.011329 0.009654
2000 1000 0.10726 0.08845 0.013593 0.012397
2000 2000 0.21065 0.10817 0.026525 0.024390
2000 3000 0.31528 0.16960 0.039772 0.036405
3000 1000 0.25415 0.14845 0.031082 0.026364
3000 2000 0.47345 0.25227 0.060887 0.051840
3000 3000 0.70612 0.36866 0.091311 0.077432
The idea is to plot it in some way I could see t1,t2,t3 and t4 for each N and M. It may be a lot of data to plot in only one graph, I know that. First of all, I have started with t1 plotting this way:
splot 'aux' u 1:2:3 w lp
and I get something like that
I would like to smooth a bit those lines and give them a different color. Is there any way to do something for it? Also any ideas to improve it in any other way would be very nice.
You're right, that is a lot of data. Changing the color of a particular dataset is pretty easy:
splot "dataset" using 1:2:3 w lines linecolor rgb "green"
Note that you can easily overlay multiple plots as follows:
splot "dataset" using 1:2:3 w lines lc rgb "green",\
"" using 1:2:4 w lines lc rgb "red"
A backslash at the end of a line is the gnuplot line-continuation character. Note that it must be the last character on the line. I've also used the pseudo-file "" which is just shorthand for the last file that gnuplot read. Finally, in this second version I used lc instead of linecolor. The gnuplot parser provides a lot of shorthand, although I suspect you already know this since you plotted w lp. (Also, please don't actually choose red and green for your plots. I think one of the biggest flaws in gnuplot is the default first 2 colors are red and green -- 1 in 20 people is red-green colorblind)
Smoothing is another story (unfortunately). plot does support a smooth option
plot "dataset" using 1:2 smooth beizer with lines #see help smooth for a list of options
Unfortunately, it appears that this option doesn't work for splot. At this point, I would write a small utility script to smooth the data in your favorite language using your favorite smoothing algorithm (plot "<utility.script mydata" u 1:2:3 ...). There are other (gnuplot-only) options, but they'd be ugly. What version of gnuplot do you have by the way? The gnuplot version is important to decide the best way to do the smoothing all in gnuplot if you decide that's still necessary.

Resources