Let me just say that i am new to gnuplot...
Trying to plot from file :
"Dataset " "Min_sup (%)" Itemsets "Rules " "Exec_time (s)"
Giorno_1 0.1 16392 260337 15.23
Giorno_1 0.2 9719 155963 11.96
Giorno_1 5.0 275 2495 6.43
Giorno_2 0.1 15023 212058 14.14
Giorno_2 0.2 8503 115766 14.62
Giorno_2 0.4 2962 43710 12.90
Giorno_2 0.8 1603 17514 10.53
Giorno_2 1.0 1223 14701 9.96
I want to plot using as x axis the the "Min_sup" column AND the "Dataset" column. Here's the problem: as you see the "Dataset" column has value that repeat and i want to show them only one time in the graph.
So basically i am searching for a way to select when to plot the the x2tics.
The gnuplot script i am using is:
set style data histograms
set grid
set terminal png nocrop enhanced font verdana 12 size 1024,768
set output "graph.png"
set xtics norangelimit
set xtics border in scale 1,0.5 nomirror rotate by -45 offset character 0, 0
set x2tics ("dataset1" "Giorno_1","dataset2" 2,"dataset3" 3,"dataset4" 4,"dataset5" 5,"dataset6" 6)
set x2tics scale 10
set xlabel "Minimum support in %"
set ylabel "# of "
set style fill transparent solid 0.6 noborder
set datafile separator " "
plot 'prova.dat' using 4:xtic(2):x2ticlabels(1) title col , \
'prova.dat' using 3:xtic(2):x2ticlabels(1) title col
It is a bit tricky to do that. Basically, you must save the "Dataset" value of the current and the previous row and compare them. If they are equal, don't set a new x2ticlabel, other use it as new label.
The values are stored with the using command:
s1 = ''
s2 = ''
plot 'prova.dat' using (s2 = s1, s1 = stringcolumn(1), $4):...
Here, s2 is assigned the value of s1 and, therefore, hold the value of the previous row. Then, s1 is assigned the string-value of the first column. With $4, the fourth column is used. This has nothing to do with the comparision, but is the 'normal' part of the using statement (using 4 and using ($4) is almost the same).
The check is done in the x2ticlabel function:
x2tic(s1 eq s2 ? 1/0 : s1)
This uses the value of the variable s1 as x2ticlabel if s1 and s2 are equal. Otherwise it uses 1/0. With this you'll get some warnings of the kind Tic label does not evaluate as string!, but that is what you want.
Finally, I removed some default settings from your script:
set terminal png nocrop enhanced font verdana 12 size 1024,768
set output "graph.png"
set style data histograms
set grid
set xtics nomirror rotate by -45
set x2tics left scale 10
set xlabel "Minimum support in %"
set ylabel "# of "
set style fill transparent solid 0.6 noborder
s1=''; s2='';
plot 'prova.dat' using (s2 = s1, s1 = stringcolumn(1), $4):xtic(2):x2tic(s1 eq s2 ? 1/0 : s1) title col , \
'prova.dat' using 3 title col
Gives (with 4.6.3):
Related
I am plotting multiplot surfaces.
I found this code 1 very helpful to plot my graph.
However, I want to label the z-axis throughout all surfaces in one plot.
I tried this set zrange[0.5:b+0.5], but nothing showed up. then I tried min_z and max_z, still, nothing showed up.
though I calculated and checked the range by the following the command.
print min_z,max_z.
can anyone please tell me how can I choose zrange with my own choice? like 1 ,2 3 4 5.
I will expand my comment as a possible answer. Multiplot is not needed for this style of plot. Here is an approximate recreation of the figure you linked to.
If you want to customize the axis labels along z, you can add a command to change the format like this: set ztic format "%.2f", and/or add additional commands of the form: set ztic add ( pi/2 "z = π/2" )
f(x,y,z) = besj0(x*x/z + y*y/z) / z
set palette cubehelix
set xyplane 0
set view 64,58
set ztics 0.2
unset key
splot for [i=1:6] z=(1.+i/6.), '++' using 1:2:(z):(f(x,y,z)) with pm3d
Answer expanded to show plotting from a series of files
Plotting from a series of files is essentially the same. The splot command again inserts a constant z value to create a plane, taking the data coordinates [x,y] from columns 1 and 3 and the f(x,y) value from column 4.
Here is an example:
set palette defined( 0 "dark-red", 1 "yellow" )
set xyplane 0
set view 74, 62, 0.85, 1.8
set border 16 # z axis only
unset xtics; unset ytics
unset key
file(i) = sprintf("map%d.dat",i)
set ztics ("File 1" 1, "File 2" 2, "File 3" 3, "File 4" 4)
splot for [i=1:4] file(i) using 1:2:(i):3 with image
I'm attempting to use gnuplot v5.4 to generate multiple graphs from one data set, though using select data from the set per graph.
I generate stats for a small program I'm developing, and write them to a CSV file:
(This CSV format is just what I've made the best progress with - I'm open to changing)
TotalPlayerCount,22
BluePlayerCount,10
RedPlayerCount,12
BluePlayerScoreTotal,50
RedPlayerScoreTotal,60
The following gives me the below graph:
cat <<"EOF" | gnuplot -p
$db <<DB
TotalPlayerCount,22
BluePlayerCount,10
RedPlayerCount,12
BluePlayerScoreTotal,50
RedPlayerScoreTotal,60
DB
set terminal windows size 2000,1000 enhanced font 'Arial,8'
set datafile separator ','
set yrange [0:100]
set boxwidth 0.1 relative
set style fill solid 1.0
plot $db using 2:xticlabel(1) notitle with boxes linestyle 1
EOF
I'm aiming for this:
which I have achieved using this:
cat <<"EOF" | gnuplot -p
$db <<DB
TotalPlayerCount,22
BluePlayerCount,10
RedPlayerCount,12
BluePlayerScoreTotal,50
RedPlayerScoreTotal,60
DB
set terminal windows size 2000,1000 enhanced font 'Arial,8'
set datafile separator ','
set yrange [0:100]
set boxwidth 0.1 relative
set style fill solid 1.0
set multiplot layout 1,2
plot $db using 2:xticlabel(1) every ::1::2 notitle with boxes linestyle 1
plot $db using 2:xticlabel(1) every ::3::4 notitle with boxes linestyle 1
unset multiplot
EOF
Is there a better or more idiomatic way to select from the data file what 'rows' to plot? These indices (in the every clause) work OK, but seem fragile.
I have previously used the trick where a ternary returning undefined in the using will cause gnuplot to ignore that row (e.g. maybe I could use it to select based on string compare) but that doesn't seem much more elegant either and I don't really enjoy how complex it makes the plot command.
One possibility that gives you a more "readable" syntax would be to use columnheaders, for which you would need to transpose your dataset. You don't necessarily need to use comma; spaces or tabs will do the trick as well:
$db <<DB
TotalPlayerCount BluePlayerCount RedPlayerCount BluePlayerScoreTotal RedPlayerScoreTotal
22 10 12 50 60
DB
Set up the layout:
set xrange [0:3]
set yrange [0:100]
set boxwidth 0.5
set style fill solid 1.0
Now you can select the column that you want to plot with column("string"), which will give you the correct y value. As for the x value, I simply took the constant number 1 for the first plot and 2 for the second one. In order to produce xticlabels one has to repeat the string:
plot $db u (1):(column("BluePlayerCount")):xticlabels("BluePlayerCount") w boxes not, \
$db u (2):(column("RedPlayerCount")):xticlabels("RedPlayerCount") w boxes not
Alternatively, you could delete the xticlabels part from the plot command and instead use: set xtics ("BluePlayerCount" 1, "RedPlayerCount" 2)
You could also automate the plot even further:
whattoplot_1 = "BluePlayerCount"
whattoplot_2 = "RedPlayerCount"
x_pos_1 = 1
x_pos_2 = 2
set xtics (whattoplot_1 x_pos_1, whattoplot_2 x_pos_2)
plot $db u (x_pos_1):(column(whattoplot_1)) w boxes not, \
$db u (x_pos_2):(column(whattoplot_2)) w boxes not
Depending on what you want to achieve in the end, you might consider using arrays and iterate over the elements:
array whattoplot[2] = ["BluePlayerCount", "RedPlayerCount"]
plot for [i=1:|whattoplot|] $db u (i):(column(whattoplot[i])) w boxes not
I hope this gives you some inspiration for how to proceed!
If you are flexible with the input data, I would organize it in the following way:
Instead of dumping everything into one file and separating it again, I would create two files, e.g. 'Counts.dat' and 'Scores.dat'.
In the (copy&paste) example below it is included in the code with datablocks $Counts and $Scores, however, if you have your data in files, simply skip the datablocks and in the plot command change it to 'Counts.dat' and 'Scores.dat', respectively.
You don't necessarily need the total count in your data, gnuplot can do this for you.
Furthermore, in the example below I introduced a third column for the color of the boxes. Check the following example as starting point for further optimization.
Code:
### multiplot with boxes and total sum
reset session
$Counts <<EOD
Red 12 0xff0000
Green 5 0x00cc00
Blue 10 0x0000ff
Yellow 7 0xffff00
EOD
$Scores <<EOD
Red 60 0xff0000
Green 30 0x00cc00
Blue 50 0x0000ff
Yellow 80 0xffff00
EOD
set yrange[0:100]
set boxwidth 0.5 relative
set style fill solid 1.0
set key left noautotitle
set grid x,y
set multiplot layout 1,2
set title "Counts"
plot sum=0 $Counts u 0:(sum=sum+column(2),column(2)):3:xtic(1) w boxes lc rgb var, \
keyentry w p ps 0 ti sprintf("Total count: %d",sum)
set title "Scores"
plot $Scores u 0:2:3:xtic(1) w boxes lc rgb var
unset multiplot
### end of code
Result:
Addition: (all data in one datablock or file)
Code:
### multiplot with boxes and total sum in a single file
reset session
$AllInOne <<EOD
# counts
Red 12 0xff0000
Green 5 0x00cc00
Blue 10 0x0000ff
Yellow 7 0xffff00
# scores
Red 60 0xff0000
Green 30 0x00cc00
Blue 50 0x0000ff
Yellow 80 0xffff00
EOD
set yrange[0:100]
set boxwidth 0.5 relative
set style fill solid 1.0
set key left noautotitle
set grid x,y
set multiplot layout 1,2
set title "Counts"
plot sum=0 $AllInOne u 0:(sum=sum+column(2),column(2)):3:xtic(1) index 0 w boxes lc rgb var, \
keyentry w p ps 0 ti sprintf("Total count: %d",sum)
set title "Scores"
plot $AllInOne u 0:2:3:xtic(1) index 1 w boxes lc rgb var
unset multiplot
### end of code
I'm working on Gnuplot 4.6 patch 4.
I want to create the bar chart with palette. I've followed this but I got error:
Tic label does not evaluate as string!
Yes, the different with the reference that I mentioned above are the xtics. My graph uses string in xtics.
Here is my sample data:
off 100.0
gpl 60.0
docs 99
vim 9.4
box 95
goo 60
ama 99.9
eba 99.98
and my plot file is:
set term pos eps font 20
set style data histogram
set style histogram rowstacked
set boxwidth 0.75
set format y "%.0f%%"
set style fill solid border -1
set xtics font "Times-Roman, 15" rotate by 45 right
#set xtics center offset 0,-1
set ytics font "Times-Roman, 15"
set palette defined ( 0 "#FFFFFF",\
1 "#FFCCCC",\
2 "#FF9999 ",\
3 "#FF6666",\
4 "#FF3333",\
5 "#FF0000",\
6 "#CC0000",\
7 "#C00000",\
8 "#B00000",\
9 "#990000",\
10 "#A00000")
set ylabel "Percentages"
#set xlabel "Services"
set yrange [70:100]
set output 'a2.eps'
plot 'a2.dat' \
using ($2):xtic(1):($2<=10 ? 0 : $2<=20 ? 1 : 2) t '' with boxes palette
Thanks for help!
The xtic label part should always be the last in a using statement. Also, when using the boxes plotting style you must specify x, y and color values:
plot 'a2.dat' \
using 0:2:($2<=10 ? 0 : $2<=20 ? 1 : 2):xtic(1) t '' with boxes palette
Note, that with boxes overwrites the histogram style you set earlier. Also, the values given in the palette aren't absolute values, but those color values are scaled to accomodate your effictive color range of [0:2].
I have a data files including multiple float-value columns such as following and I want to plot some columns in gnuplot.
1.08 1.6 4.83
1.53 2.5 5.95
2.11 3.2 6.1
2.60 4.1 7.0
I want to have x2-axis by following:
set xtics nomirror
set x2tics
set autoscale xfix
set autoscale x2fix
set ylabel 'Y_H
set xlabel 'Y_O'
set x2label 'Y_C'
p 'datafile' u 1:2 w l ls 1 t '',\
'' u 1:(NaN):x2ticlabels(3) axes x2y1 w l ls 1 t ''
This way displays every single tic and It's label on the x2 axis. I would like to set custom labels for x2-axis such as 4,5,6,7 and their tics to write. How can I have custom labels and tics on x2-axis?
x2tics behave the same way as xtics so all functions available for xtics are also applicable to x2tics.
Set a range by:
set x2range [1:5]
This command will give you a range of 1 to 5 on the x2 axis.
If you want to set custom labels then:
set x2tics ("one" 1, "two" 2, "three" 3, "four" 4, "five" 5)
This command will give you the words inside double quotes at x2=1, x2=2 and so on.
In your case you can get numerical values on x2 axis by using set x2range [4.83:7] and changing second plot to 1:(NaN):3
I have an infrared spectrum for a compound of interest that I would like to plot, and I have a spectrum.dat file with all of the data points. It is of the form:
# X Y
300 100
301 100
302 99
303 70
...
3999 98
4000 100
I would like to plot this using an x axis typical of IR spectra, but I am having trouble doing so. If you are unfamiliar, this is what a typical IR spectrum might look like (aside from the labels on the graph itself). Notice that the x-axis is reversed, and that it abruptly doubles its scaling above 2000 units (reciprocal centimeters). Is there a way to coerce Gnuplot into plotting my data this way? I so far have managed to come up with the following script:
# Make an SVG of size 800x500
set terminal svg size 800,500 fname 'CMU Sans Serif' fsize '10'
set output 'ir.svg'
# Color definitions
set border linewidth 1.5
set style line 1 lc rgb '#a0a0a0' lt 1 lw 2 pt 7 # gray
# Format graph
unset key
set xlabel 'Wavenumbers'
set ylabel 'Transmittance'
set xrange [4000:300]
# Plot data
plot 'spectrum.dat' with lines ls 1
This reverses the x-axis nicely, but I can't figure out how to change the scaling in such an unusual way.
As a chemist I am motivated to answer...
As far as I know gnuplot doesn't easily allow for arbitrary axis scaling (unless anyone has bright ideas about how to use set link). My strategy in this kind of situation is to plot the two halves separately and have them join seamlessly:
#!/usr/bin/env gnuplot
set terminal png size 800,500
set output 'ir.png'
set xlabel 'Wavenumbers' offset 20
set ylabel 'Transmittance'
set tics out nomirror
set key bottom right
set bmargin 4
set yrange [0:1]
set multiplot layout 1,2 title 'IR Spectrum of Cholesterol'
# left half of plot
set xrange [4000:2000]
set rmargin 0
set border 7
plot 'cholesterol.txt' notitle
# right half of plot
set xrange [1999:300]
set lmargin 0
set rmargin 2
set border 13
unset xlabel
unset ylabel
unset ytics
plot 'cholesterol.txt' title 'Cholesterol'
unset multiplot
My one quibble is that the 2000 is written twice and looks bolder on my screen, but I will leave fidgeting with the tics to you.
andyras' answer is a nice one, this is an arguably simpler (more elegant :-P) solution in terms of layout options. This should also be a more universal solution. If there are not too many tics (read below the figure if there are too many), then this could be done scaling the curve itself beyond 2000, and then adding all the tics by hand. Since I don't have IR spectrum data available I will use the dummy file "+" and plot log(x) from 4000 to 500:
xmax=4000 ; xmin = 500
pivot = 2000 ; rescfactor = 2.
rescale(x) = (x >= pivot ? x : pivot + rescfactor*(x-pivot))
set xrange [rescale(xmax):rescale(xmin)]
set xtics ("4000" 4000, "3000" 3000, "2000" 2000, \
"1500" rescale(1500), "1000" rescale(1000), "500" rescale(500))
plot "+" u (rescale($1)):(log($1)) w l
In your case you just substitute log($1) by 2 or whatever you're plotting.
In newer versions of gnuplot (starting from 4.4) adding the tics can be done automatically using a loop:
xmax = 4000 ; xmin = 500 ; step = 500
set xtics (sprintf("%i",xmax) rescale(xmax)) # Add the first tic by hand
set for [i=xmin:xmax-step:step] xtics add (sprintf("%i",i) rescale(i))
Starting from gnuplot 4.6 also a different for construction can be made using do for:
do for [i=xmin:xmax-step:step] {set xtics add (sprintf("%i",i) rescale(i))}