Populate spiderplot from data file in gnuplot 5.4 - gnuplot

The recent release of gnuplot 5.4 came out with a lot of neat new features, to include the use of "spiderplots" (sometimes also called radar plots, etc.). Following their demos, I've been able to successfully plot a spiderplot using local data defined in the script. However, I can't seem to figure out how to do it using a data file (e.g. *.csv). I'd really like to do one similar to the last one on the demo list (multiple data series, markers, shading, etc.), but can't figure out the syntax on how to use the data from the file.
For something to work with, I've copied the array data from that last example script and converted it into a *.csv format. Feel free to use that as an example input file. Thank you for any/all help!
Array1,Array2
15,25
75,25
20,50
43,50
90,75
50,50

If you have the data file 'test.csv', the following script can be used to reproduce the last plot in demo.
set size ratio 1 1,1
# set title "To plot from 2 different files or arrays, use 'newspiderplot'"
set datafile separator comma
set spiderplot
set style spiderplot fs transparent solid 0.2 border lw 1 pt 6 ps 2
set for [i=1:6] paxis i range [0:100]
set paxis 1 tics font ',9'
set for [i=2:6] paxis i tics format ""
set grid spider lt black lc "grey" lw 0.5 back
set style data spiderplot
plot \
keyentry with spiderplot lc 3 lw 3 title "Array #1", \
for [i=1:6] "test.csv" every ::i::i using 1 lc 3 lw 3 title sprintf("Scale %d",i), \
newspiderplot, \
keyentry with spiderplot lc 4 lw 2 title "Array #2", \
for [j=1:6] "test.csv" every ::j::j using 2 lc 4 lw 2 notitle
You have 2 series of 6 axis data. The loop body of the following code picks one value of row-number i and column-number 1 from "test.csv", which is same value in original code using 'Array1[i]'.
This code
for [i=1:6] "test.csv" every ::i::i using 1 lc 3 lw 3 title sprintf("Scale %d",i), \
Original code
for [i=1:|Array1|] Array1 using (Array1[i]) lc 3 lw 3 title sprintf("Scale %d",i), \
FYI, |Array1| is the expression which means the number of elements in Array1.

Related

Bubble graphs - how to use?

Is it possible to combinate "normal points" and "bubble points"? I have two sets of data - file1.txt and file2.txt and for one of them (file2.txt) I would like to use points like http://gnuplot-tricks.blogspot.com/2009/06/
How to compose this into code please? When I use the code from that webpage how to plot another data. I tried this:
f(x) = A*exp(-x*x/B/B)
rx=0.107071; ry=0.057876; A = 1; B = 0.2; C=0.5*rx; D=-0.4*ry
g(u,v) = (2*cos(u)*v*rx+C)*(2*cos(u)*v*rx+C)+(3.5*sin(u)*v*ry+D)*(3.5*sin(u)*v*ry+D)
unset key; unset colorbox; set view map
set xrange [-0.15:5.2]; set yrange [-0.7:0.95]
set parametric; set urange [0:2*pi]; set vrange [0:1]
set isosamples 20, 20; set samples 30
set palette model HSV functions 1, 1-f(gray), 1+2*f(gray)
splot cos(u)*rx*v-0.13335347,sin(u)*ry*v+2.7730389, g(u,v) w pm3d, \
cos(u)*rx*v-0.11625481,sin(u)*ry*v+3.5312312, g(u,v) w pm3d, \
cos(u)*rx*v-0.14454222,sin(u)*ry*v+3.6412394, g(u,v) w pm3d, \
cos(u)*rx*v-0.070272446,sin(u)*ry*v+3.8070912, g(u,v) w pm3d, \
cos(u)*rx*v-0.10077238,sin(u)*ry*v+4.090774, g(u,v) w pm3d, \
'file1.txt' using 2:1:(0.0):2 with points pt 7 ps 1 palette
but file2 is not splot. Thank you very much
Here is a variant of the "trick" shown in your second link. I have extracted the customized point styles into a pre-defined set of linetypes. This makes the plot command itself simpler, and it is easier to reuse the definitions in multiple plots.
set linetype 101 ps 3.0 pt 7 lc rgb "#ff0000"
set linetype 102 ps 2.6 pt 7 lc rgb "#ff2222"
set linetype 103 ps 2.2 pt 7 lc rgb "#ff4444"
set linetype 104 ps 1.8 pt 7 lc rgb "#ff6666"
set linetype 105 ps 1.4 pt 7 lc rgb "#ff8888"
set linetype 106 ps 1.0 pt 7 lc rgb "#ffaaaa"
set linetype 107 ps 0.6 pt 7 lc rgb "#ffcccc"
set linetype 108 ps 0.2 pt 7 lc rgb "#ffeeee"
set border back
plot for [LT=101:108] 'silver.dat' using 1:2 with point lt LT notitle
Please clarify what exactly what properties your plot needs to have.
(1) The term "bubble plot" usually refers to a plot in which each point is drawn as a circle with additional properties encoded by changing the size, color, or other property of the circle. Gnuplot can do that quite well. A good example can be found in the online demo collection: Hypertext bubble chart In this case the size of the circle is used to indicate relative population and additional information is encoded as hypertext (pop-up text box) attached to that point. Variable color could easily be added as well. The png version below does not include the hypertext.
(2) The example you link in the query does not appear to encode any additional information into the shape or color of the point but it does use a fancy glyph for each point rather than a simple dot or cross. Gnuplot can do that also. It depends on exactly what set of symbols or glyphs you want to use. If you can find a font providing appropriate glyphs then one way is shown here:
shape(i) = (i%4 == 0) ? "⊕" : (i%4 == 1) ? "⊙" : (i%4 == 2) ? "⊚" : "⦾"
set grid x y z vertical
splot 'silver.dat' using 1:2:3:(shape(int(column(0))) with labels textcolor "forest-green"
More complicated options are also possible but may depend on exactly what you need and what output format (gnuplot "terminal type") is acceptable.

Gnuplot plotting wrong lines and some strange values as well

I am using gnuplot to postprocess some calculation that I have done and I am having hard time getting gnuplot to select the right lines as it is outputting some strange values that I do not know where come from.
The first 200 points of the results start in line 3 and stop in 202 but that is not working when I use every ::3::202.
Does anyone have any suggestions of what I am doing wrong?
Gnuplot image:
Datafile
set terminal pngcairo transparent nocrop enhanced size 3200,2400 font "arial,40"
set output "Mast41_voltage_muffe.png"
set key right
set samples 500, 500
set xzeroaxis ls 1 lt 8 lw 3
set style line 12 lc rgb '#808080' lt 0 lw 1
set style line 13 lt 0 lw 3
set grid back ls 12
set decimalsign '.'
set datafile separator whitespace
set ylabel "Spenna [pu]"
set xlabel "Timi [s]"
plot "mrunout_01.out" every ::3::202 using 2:3 title '5 ohm' with lines lw 3 linecolor rgb '#D0006E',\
"mrunout_01.out" every ::203::402 using 2:3 title '10 ohm' with lines lw 3 linecolor rgb '#015DD4',\
"mrunout_01.out" every ::403::602 using 2:3 title '15 ohm' with lines lw 3 linecolor rgb '#F80419',\
"mrunout_01.out" every ::603::802 using 2:3 title '20 ohm' with lines lw 3 linecolor rgb '#07826A'
unset output
unset zeroaxis
unset terminal
every refers to the actual plottable points. In your case, you have to skip 2 lines and the bunch of data at the end of your datafile.
Since you know the actual lines you need to plot I would pre-parse the file with some external tools like sed
So you can omit the every and your plot line becomes:
plot "< sed -n '3,202p' mrunout_01.out" using 2:3 title '5 ohm' with lp lw 3 linecolor rgb '#D0006E'
With yor datafile as it is, gnuplot has problems reading it. It can't even run stats on it:
stats 'mrunout_01.out'
bad data on line 1 of file mrunout_01.out
There is no need for using external tools, you can simply do it with gnuplot.
It's advantageous with your data that it is regular, every 200 points plotted in a different color.
And the data you want to plot is separated by one empty line from some additional data at the end of the file which you don't want to plot.
So, you simply address the 4th set of 200 lines in the 0th block via every ::600:0:799:0.
From help every:
Syntax:
plot 'file' every {<point_incr>}
{:{<block_incr>}
{:{<start_point>}
{:{<start_block>}
{:{<end_point>}
{:<end_block>}}}}}
Comments:
you can skip two lines at the beginning of the files with skip 2
you can plot your curves in a loop plot for [i=1:4] ...
you can define your color myColor(n) via index n from a string "#D0006E #015DD4 #F80419 #07826A"
you can define the legend myTitle(n) also from a list "5 10 15 20"
Script: (tested with gnuplot 5.0.0, version at the time of OP's question)
### plot parts of a file in a loop
reset session
FILE = "SO36103041.dat"
myColor(n) = word("#D0006E #015DD4 #F80419 #07826A",n)
myTitle(n) = word("5 10 15 20",n)
set xlabel "Timi [s]"
set ylabel "Spenna [pu]"
set yrange[0:30]
plot for [i=1:4] FILE u 2:3 skip 2 every ::((i-1)*200):0:(200*i-1):0 \
w l lw 3 lc rgb myColor(i) ti myTitle(i)
### end of script
Result:

GNUplot - plot data file (simple X and Y columns) - setting suitable color and scale on a figure

I have a simple file with two columns:
1 0.005467
2 0.005333
3 0.005467
4 0.005467
5 0.005600
6 0.005600
7 0.005467
8 0.005467
In the first column I have the x-axis values, while on the second column I have y-axis values. I would like to plot a figure of this data. I wrote a gnuplot script for this:
#!/usr/bin/gnuplot
set xlabel "test"
set ylabel "value"
set grid ytics lt 0 lw 1 lc rgb "#bbbbbb"
set grid xtics lt 0 lw 1 lc rgb "#bbbbbb"
set autoscale
set terminal postscript portrait enhanced mono dashed lw 1 'Helvetica' 14
set style line 1 lt 1 lw 3 pt 3 linecolor rgb "red"
set output 'out.eps'
plot 'data.txt' using 2:1 w points title "tests"
And, the output:
But of course, as a newbie in gnuplot, I have some troubles:
How to change the crosses on the fingure into dots?
How to change the color of the dots, to let's say, red? ( my command in my gnuplotscript seems not to work at all ...)
For the first test the adequate, accurate, exact value is 0.005467 but on my figure it doesnt look like so... I would like to place the dot on my figure for the first, second, third, (so on) test on the exact place, where is appropriate value.
How to add a grid to my figure? - SOLVED
How to get rid of the ugly text: 'data.txt' using 1:2 and replace it with a legend? - SOLVED
EDIT (SOLVED ISSUE NO 5)
plot 'data.txt' using 1:2 w points title "tests"
EDIT (SOLVED ISSUE NO 4)
set grid ytics lt 0 lw 1 lc rgb "#bbbbbb"
set grid xtics lt 0 lw 1 lc rgb "#bbbbbb"
You should read a bit in the documentation about all your commands!
Several remarks:
If you want colored points, you shouldn't use the mono (i.e. the monochrome) option, but rather color.
Your definition of the line style is correct, but in order to use it you must use linestyle 1 when plotting. Otherwise the linetype 1 is used. Compare:
set style line 1 lt 1 lw 3 pt 3 linecolor rgb "red"
plot x, 2*x linestyle 1
In order to see all the dots of a terminal, use the test command:
set terminal postscript eps enhanced color dashed lw 1 'Helvetica' 14
set output 'test.eps'
test
set output
You see, that for filled dots you must use pt 7.
I'm sure, that the points are shown at the correct values. Use
set ytics add (0.005467)
to see this.

Plotting from a data file - dots on a figure are not in the exact positions

My data file Im using for plotting:
0.005200 1
0.005333 2
0.005333 3
0.005333 4
0.005333 5
0.005467 6
0.005467 7
0.005467 8
My GNUplot script used for plotting:
#!/usr/bin/gnuplot
set xlabel "test"
set ylabel "value"
set grid ytics lt 0 lw 1 lc rgb "#bbbbbb"
set grid xtics lt 0 lw 1 lc rgb "#bbbbbb"
set autoscale
set terminal postscript portrait enhanced color dashed lw 1 'Helvetica' 14
set style line 2 lc rgb 'red' pt 7 # circle
set output 'test.eps'
plot 'data.txt' using 2:1 with points ls 2 title "time series plot"
Output image generated with GNUplot:
As you see in the data file I posted, value for the second, third, fourth and the fifth test is 0.005333. (As well as for the sixth, seventh and eighth test - there is a value of 0.005467).
But you can't see that on a figure - take a look at it. For the second, third, fourth and the fifth test the value on the figure is in somewhere between the 0.0053 and 0.00535 and I need the dots to be in the EXACT position on figure as its on the text file.
I have so much such files, is there any "portable" way to use it for every file I have?
The points are of course in the correct position. Add
set ytics add (0.005333, 0.005467)
to your script to see this:

gnuplot troubles - getting double plots

I have a script I wrote that selects a block from a data file based on a command line argument. Up until now it has worked just fine. Now the graphs I'm getting out for the first 26 blocks have two sets of data in them. The data file should have about 190 blocks of data. I've thought and probed for an hour and I still have no idea why this might be happening. Here is the gnuplot script.
gnuplot << EOF
reset
set terminal png small size 1280,480
set output "graph_$1.png"
set yrange [-0.5:5.5]
set autoscale x
set lmargin 17
set label "SPILL" at -1,.5 right
set label "ON" at -1,1 right
set label "OFF" at -1,0 right
set label "DATA" at -1,2.5 right
set label "CLOCK" at -1,4.5 right
set xtics in scale .1 4 format ""
set grid
unset ytics
set key at -1,3.75 right
plot 'plotting' using 0:1 every :::$1::$1 title 'Results' with lines lt 1 lw 2, \
'' using 0:2 every :::$1::$1 notitle with lines lt 1 lw 2, \
'' using 0:3 every :::$1::$1 title 'Expected' with lines lt 3 lw 3, \
'' using 0:4 every :::$1::$1 notitle with lines lt 3 lw 3, \
'' using 0:5 every :::$1::$1 notitle with lines lt -1 lw 3
EOF
So when I make $1 to be anything from 0 to 26 it gives me multiple plots on one graph. If it's anything from 27 to 99 I know I get only one plot with only the data I want. I can't even find out where the second set of data on those first plots comes from. Sifting through the text in my data file to match it up would be extraordinarily tedious. Any help or advice on how to fix this double graphing would be greatly appreciated. Thank you.

Resources