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

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.

Related

Gnuplot - Trying to create a waterfall/ fence plot

I try to create a nice waterfall map with gnuplot showing the development of an optical spectrum with current. My goal is to achieve something close to this :
A waterfall plot
I have tried this command
splot [][1160:1200][-80:-30] "Waterfall.txt" u 1:2:3 w l lw 3 lc rgb 'black'
The "Waterfall.txt" file has the format suggested in the accepted answer here Gnuplot: fence plot from data.
I have ignored z-data values lower than -80, substituting them with NaN.
The outcome is shown in the next image link.
My attempt
As you can see, compared with the previous figure, this is confusing to the reader. How can I fix it in order for it to be close to the first image and thus more clear to the viewer ?
Edit:
Thanks to #Ethan's answer it worked. The outcome is shown in the figure below. The only problem is the transparency of each fence, that reveals partially the subsequent fences.
The new attempt
Assume twenty 2D files each containing Y and Z:
Gnuplot version 5.2
filename(i) = 'silver.dat'
set pm3d scansauto
set style fill solid noborder
set xyplane at 0
set log z
unset key
splot for [k=20:1:-1] filename(k) using 1:(k):2:(1.0):2 with zerrorfill \
fc "white" lc "black" lw 2
I don't have your data files so I use the same file 20 times for the purpose of illustration. It is based on the zerror demo in the gnuplot distribution and online demo set.
Note that the base of each 'fence' is set to (z=1.0) rather than zero because of the log scale on z.
The figure shown was made using a newer gnuplot. It uses partial transparency and a fancier bounding box that isn't in 5.2

gnuplot : Can the splot command generate impulses in the x-y plane?

Does anyone know if the splot command can be used to generate impulses in the x-y plane?
For example, I have the following segment of gnuplot code;
splot \
\
u, 0, cos(u) linecolor "red" notitle with impulses, \
u, sin(u), 0 linecolor "blue" notitle with impulses, \
u, sin(u), cos(u) linecolor "green" notitle
The first (red) plot successfully generates impulses in the x-z plane, i.e. vertically oriented impulses. The second (blue) plot however, does not generate impulses in the x-y plane, i.e. horizontally oriented impulses, as I would like! Does anyone know how to accomplish this? Furthermore, does anyone know if it possible to use any of the gnuplot iteration commands to do this? Ideally, I would like to have impulses - or something similar like arrows, from the x-axis to the third (green) plot as well.
Thanks in advance.
The blue graph is plotted, but not like you expect. Try changing the 0 to e.g. 0.1:
The reason for this is that in 3D plots, the impulses style always plots lines from z=0 to the actual z value.
What you want is not possible with impulses.
You might be able to adapt this filledcurves example from gnuplotting.org.
The following image was generated with gnuplot. The green lines radiating outward from the x-axis (Theta axis in the image) were implemented using arrows without heads.
I could have simulated impulses for the blue plot using this same approach of arrows without heads, but I have omitted it from the image in order to assist with visual clarity. So, while it appears that impulses can't be used in any orientation other than vertically, arrows can be used for the same effect!
Although this image provides a good visual representation of Euler's formula, I think an even better one is achieved with a 3D "fly-around" of the plot as Theta increases.
The gnuplot code which I used to implement the green arrows, was as such;
set \
\
for [x_new = 0:max_plot_index] \
\
arrow from (x_new * plot_inc),0,0 to (x_new * plot_inc),sin(x_new * plot_inc),cos(x_new * plot_inc) linecolor "green" nohead
where max_plot_index was increased by 1 for every frame of the "fly-around" animation and plot_inc was set to (4 * pi)/100.
I hope someone finds this helpful!

Gnuplot: hide plots by default?

I'm Using Gnuplot 4.6 (I'll change to 5.0 if required) with the wxt terminal on Ubuntu 14.04. I have a single window with a single plot with multiple curves like this:
plot 'file1' u 1:2 w l, '' u 1:3 w lp, 'file2' w i, '' u 1:3 wp pt 7 etc
I can click the keys of curves to hide/show them. Can I make some of them hidden by default?
This is useful as I am comparing computation outputs and use a lot of labels and different lines/points/impulses etc for different data, and the graph gets really messy. And many times I only need some content for a few seconds at the time, so I end up hiding most plots, to show them when needed.
Any advice is welcome! Cheers /J
There had indeed been a discussion about such a feature, i.e. change the visibility of plots via some option, see http://sourceforge.net/p/gnuplot/mailman/message/31315515/. As far as I know, that wasn't implemented yet.
If it helps you, there are some hot keys which allow you to change the visibility of many plots:
show bind
gives the following hot keys
...
i `builtin-invert-plot-visibilities`
...
V `builtin-set-plots-invisible`
v `builtin-set-plots-visible`
So, you can invert the visibility of all plots (i), hide all plots (V), and show all plots (v).

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.

Is it possible to set the "linetype" in gnuplot while using "linecolor variable"?

I have a tab-separated data file containing a number of (double-blank-line-separated) datasets and I want to plot a line for each of them. I want to be able to set the linetype (by this I'm referring to solid/dashed/dotted). I want each line to be a different color.
I can plot them all different colors using this:
plot 'example.dat' using 1:2:(column(-2)) with lines linecolor variable
And I can set the linetype but plot them all the same color using this:
plot 'example.dat' using 1:2:(column(-2)) with lines linetype 5
But when I combine them, the linetype is not what I set it to (in this case I just get a solid line).
plot 'example.dat' using 1:2:(column(-2)) with lines \
linetype 5 linecolor variable
Is there a way to achieve this?
I'm using gnuplot 4.6, tried with the x11 and postscript terminals.
This looks like a bug to me. Unfortunately, I don't think too many gnuplot devs hang out on StackOverflow, so we might not ever find out. (I would encourage you to submit a bug report though and keep me updated on any progress that might be made)...
If you're really using column(-2) to pick out the colors, the problem becomes a lot easier and you should be able to do that using plot iteration (as long as you know an upper limit on the number of datasets).
NDSET=3 #This will issue a warning if NDSET is too big, but will still work.
plot for [IDX=0:NDSET] 'example.dat' index IDX using 1:2 with lines linetype 5 linecolor IDX+1
The indexing starts from 0 and corresponds to column(-2). Linecolor 0 isn't defined (I don't know why gnuplot uses two different conventions here -- I suppose because in theory the colors corresponding to any particular linestyle are terminal dependent, so it doesn't really matter too much anyway...)

Resources