Gnuplot : xtics - place strings at tics - gnuplot

I am new to gnuplot, and am trying to create a stacked histogram for a project. The problem I am running into is, that I am not able to put ticlabels on the x-axis (even if I could, they are not getting formatted in a neat way). My gp file is as follows:
Here is a snapshot of my data file:
CC P1-X P1-Y P2-X P2-Y
1 0.1097586 0.3262812 1.980848 5.9098402
2 0.1010986 0.2988812 0.9966702 5.8378412
3 0.4017474 0.7559452 4.41813 11.7404132
4 0.1028442 0.2974772 1.418744 6.0554552
5 0.1097316 0.3216112 1.967492 5.8007364
6 0.954794 0.3004874 0.9568386 5.778537
And here is my gp file:
set title "GCC compilation option by average execution time as stacked histogram"
set terminal jpeg medium
set output "histosmalldata.jpeg"
set boxwidth 0.9 absolute
set style fill solid 1.00 border -1
set key autotitle columnheader
set key outside right top vertical Left reverse enhanced autotitles columnhead nobox
set key invert samplen 4 spacing 1 width 0 height 0
set style histogram rowstacked title offset character 0, 0, 0
set style data histograms
set xtics border in scale 1,0.5 nomirror rotate by -45 offset character 0, 0, 0
set xtics norangelimit
set xtics ("O2-ffast-math-finline-functions" 1, "O2-funroll-loops-march=barcelona-ffast-math-finline-functions" 2, "GCCFLAGS_O0" 3, "O2-ftree-vectorize-funroll-loops-march=barcelona" 4, "GCCFLAGS_O2" 5, "O2-ftree-vectorize-funroll-loops-ffast-math" 6)
set xtics 1,6 nomirror
set ytics 0,100 nomirror
set ytics 1
set yrange [0:20]
set ylabel "Time"
set xlabel "GCC Compiler Options"
plot 'smalldata' using 2:xtic(1) ti col, '' using 3 ti col, '' using 4 ti col, '' using 5 ti col
This is the image of the graph:
Now, in the x axis, I am having 1,2,3 - 6 which I don't want, instead, I would want "O2-ffast-math-finline-functions" for 1 and so on in a neat formatted way.
I wrote this script after consulting some examples from gnuplot page and do not have a good understanding of some of the verbs, so apart from the solution, any general comments are welcome.
Thank you,
Sayan

You should not overwrite your xtics settings after you specified what you want.
Put all options into a single set command:
set xtics border in scale 1,0.5 nomirror rotate by -45 offset character 0, 0, 0\
norangelimit\
("O2-ffast-math-finline-functions" 1,\
"O2-funroll-loops-march=barcelona-ffast-math-finline-functions" 2,\
"GCCFLAGS_O0" 3, "O2-ftree-vectorize-funroll-loops-march=barcelona" 4,\
"GCCFLAGS_O2" 5, "O2-ftree-vectorize-funroll-loops-ffast-math" 6)
Note that you can escape the newline with a backslash as the last character of the line.

I figured out, that I do not actually need to specify ticlabels because that information is in my source file.
So I modified my source file like:
set title "GCC compilation option by average execution time as stacked histogram"
set terminal png size 1500,1200 font "/Library/Fonts/Times New Roman Bold.ttf, 13"
set output 'hist_gcc_1.png'
set boxwidth 0.9 absolute
set style fill solid 1.00 border -1
set key outside right top vertical Left reverse enhanced autotitles columnhead nobox
set key invert samplen 4 spacing 1 width 0 height 0
set style histogram rowstacked title offset character 0, 0, 0
set datafile missing '-'
set style data histograms
set xtics border in scale 1,0.5 nomirror rotate by -45 offset character 0, 0, 0 norangelimit
set ytics 0,100 nomirror
set ytics 1
set yrange [0:20]
set ylabel "Time"
set xlabel "GCC Compiler Options"
plot 'data' using 2:xticlabels(1) ti col, '' using 3 ti col, '' using 4 ti col, '' using 5 ti col
My dat file looks like:
CC P1-X P1-Y P2-X P2-Y
O2-ffast-math-finline-functions 0.1097586 0.3262812 1.980848 5.9098402
O2-funroll-loops-march=barcelona-ffast-math-finline-functions 0.1010986 0.2988812 0.9966702 5.8378412
GCCFLAGS_O0 0.4017474 0.7559452 4.41813 11.7404132
...

Related

How to move and manage overlapping of x ticks with axis in Gnuplot

I am trying to plot an inlet graph which is shown in Figure. Being an inlet graph it is needed to show x tics and y ticks of relatively big sizes for clear visibility. But when I increase the fonts as,
set xtics font ", 40"
tics overlaps with axis. I increased the plot size set term png size 1000, 1000 but still the issue persists. Kindly suggest if there is a way to move the tics below or to a desired position in graph.
Edit:
The gnuplot script looks like this,
set term png size 1000, 1000
set output "b_vs_N.png"
set style fill solid
set style circle radius 0.001
FIT_LIMIT=1.e-14
set yrange [0.15:0.25]
set style fill solid
set style circle radius 0.001
set xtics 10
set ytics 0.03
set border 15 back lw 6
set xtics font ", 40"
set ytics font ", 22"
set ylabel "b" enhanced font "1 {,40}"
set xlabel "N_i" font "1 {,40}"
set lmargin 12
set bmargin 4
set palette model HSV
set palette rgb 3,2,2
set palette maxcolors 12
set view map
AA(x)=a+b*x+c*x**2
fit AA(x) "data.txt" using 1:2 via c, b, a
plot "data.txt" using 1:2 lt 1 pt 11 ps 2.0 lc rgb "black" notitle, AA(x) w lines lw 2 lc rgb "sienna1" notitle
Your example is uncomplete without code and therefore difficult to reproduce. Please check help xtics. There is the option offset.
Maybe the following example helps to solve your issue.
In the example below no special offset seems to be necessary, i.e. offset 0,0, but you can shift and adjust the labels in x and y direction.
Code:
### tic label offset
reset session
set multiplot
plot sin(x)/x
set origin 0.07, 0.6
set size 0.3,0.3
set xrange [0:10]
set xtics 5 out font ",20" offset 0,0
plot x**2
unset multiplot
### end of code
Result:

Show error bars in a multiaxis plot in Gnuplot

I have a dataset (show-errorbar.dat) containing:
Model# DE IE Error
Apple -4.6 -128.9538 4.0
Huawei -5.2 -176.6343 5.3
One-Pro -5.2 -118.1106 3.2
#!/usr/bin/gnuplot
#set terminal pdfcairo enhanced color font 'Helvetica,12' linewidth 0.8
set terminal png
set output 'BrandError.png'
set boxwidth 1.0 relative
set bmargin 5
set style fill solid border -1
set xtic rotate by -45 scale 0
#set auto x
set style line 81 lt 0 lc rgb "#808080" lw 0.5
set grid xtics
set grid ytics
set grid mxtics
set grid mytics
set grid back ls 81
set arrow from graph 0,first -4.6 to graph 1, first -4.6 nohead lw 2 lc rgb "#000000" front
set border 11
set border lw 2.0
set xtics font ",11"
set ytics font ",14"
set tics out
set ytics nomirror
set y2tics
set y2tics font ",14"
set mxtics 10
set mytics 2
set my2tics 2
set yrange [-10:0]
set y2range [-260:0]
set key left bottom
set y2label offset -2
set ylabel offset 2
set ylabel 'DE' tc rgb "red"
set y2label 'IE' tc rgb "green"
set style data histograms
set style histogram cluster gap 2
set linetype 2 lc rgb 'red'
set linetype 3 lc rgb 'yellow'
set linetype 4 lc rgb 'green'
plot 'show-errorbars.dat' using 2 ti 'DE' lc 2 axis x1y1, '' u 3:xticlabels(1) ti 'IE' lc 4 axis x1y2
set output
enter image description here
I would like to plot a histogram comparing DE vs IE and also show error bars (data in column 4) for the IE values.
Please any help on how to go about it.
There is a variant histogram style for exactly that purpose
set style histogram errorbars gap 2 {lw W}.
Here is the help section from the docs:
The `errorbars` style is very similar to the `clustered` style, except that it
requires additional columns of input for each entry. The first column holds
the height (y value) of that box, exactly as for the `clustered` style.
2 columns: y yerr bar extends from y-yerr to y+err
3 columns: y ymin ymax bar extends from ymin to ymax
The appearance of the error bars is controlled by the current value of
`set errorbars` and by the optional <linewidth> specification.
Updated answer
Notes:
You can't mix axis choice within a single histogram. So I have removed the axes x1y1 and axes x1y2 from the plot command. Since you have explicitly given the range for both y1 and y2, the plot border and labels are not affected.
However since the green bars are now being plotted against y1, we have to scale them so that the y2 axis labels apply. So the column 3 and column 4 values will be divided by 26, which is (y2 range) / (y1 range)
In "histogram errorbars" mode each plot component looks for an extra column of data to determine the size of the errorbar. Since your column 2 data has no corresponding column of errors, we dummy it up to use all a constant not-a-number (no data) value: (NaN)
Your data contains a line of columnheaders, which could confuse the program if it thinks this is a line of data. There are a number of ways you can tell the program to skip this line; I have used set key autotitle columnhead for convenience and because it is supported by old versions of gnuplot. If you have a current version it would be better to use instead set datafile columnheaders.
I have kept all of your commands except that the plot command is replaced by the following 3 lines:
set style histogram errorbars gap 2 lw 1.5
set key autotitle columnhead
plot 'show-errorbars.dat' using 2:(NaN) ti 'DE' lc 2, '' u ($3/26.):($4/26.):xticlabels(1) ti 'IE' lc 4

Customizing gnuplot clustered histogram x-axis labels

I have a gnuplot script
set terminal qt size 850,500 enhanced font 'Verdana,12' persist
set boxwidth 0.9 absolute
set ylabel "Duration in milliseconds" #font "Arial 14"
set tics font "Monospaced,bold 14"
set style fill solid 1.00 border lt -1
set key inside right top vertical Right noreverse noenhanced autotitle nobox
set style histogram cluster gap 1 title textcolor lt -1
set minussign
set datafile missing '-'
set style data histograms
set xtics border in scale 0,0 nomirror rotate by -45 autojustify
set xtics norangelimit
set xtics ()
set title "Integer d-ary heap performance"
set yrange [0:*]
set style line 1 lt 1 lc rgb "#000000"
set style line 2 lt 2 lc rgb "green"
plot 'integer_heap_benchmark_dary.dat' using 2:xtic(1) linecolor rgb "#5555ff" title col, \
'' using 3:xtic(1) linecolor rgb "#f4dc42" title col, \
'' using 4:xtic(1) title col
which looks like this:
What I want to achieve is:
Move each x-axis label a little bit to the left so that it "points" to the center of each cluster,
Change the font and size of the x-axis labels.
I have put an effort to find the answers on my own, yet without any success.
Try something like
set tics font "Courier,24"
to set the font.
To center the labels, try something like
set xtics offset -3
You'll have to experiment with the values.

GNUPLOT - Can't display values over the bar

I'm trying make simple histogram with this file '.dat'
Moment "Energy consumed (MWh)"
"Apr-16" 2011.4
"May-16" 1869.6
"Jun-16" 1899.0
"Jul-16" 1659.0
"Aug-16" 1740.6
"Sep-16" 1670.0
For this purpose I have written the following script
#!/usr/bin/gnuplot
set term postscript
set terminal pngcairo nocrop enhanced size 700,700 font "arial,18"
set termoption dash
set output out
set boxwidth 0.5 absolute
set border 0
set style fill solid 1.00 border lt -1
set key off
set style histogram clustered gap 1 title textcolor lt -1
set datafile missing '-'
set style data histograms
set xtics border in scale 0,0 nomirror autojustify
set xtics norangelimit
set xtics ()
unset ytics
set title titulo
set yrange [0.0000 : limite] noreverse nowriteback
show style line
set style line 1 lt 1 lc rgb color lw 1
## Last datafile plotted: "immigration.dat"
plot fuente using (column(0)):2:xtic(1) title titulo ls 1 with boxes, '' using 0:2:2 with labels
In this case out is the output filename, titulo is the label that appears on the top of the image output, limite is the value that I use as biggest value on y-axi, and fuente is the source filename.
The result is this
I am trying display the values over the bar with some offset because I need the values over the bars and not inside the bars. I would need separate I am trying with code like:
plot fuente using (column(0)):2:xtic(1) title titulo ls 1 with boxes, '' using 0:($2 + 0.5):2 with labels
because I have seen many sites where they get it doing $2 + 0.5 but this it doesn't work for me.
What should I do? Please help me I am completly lost. Thanks in advance.
Use the offset parameter for the with labels plotting styles. With this you can add a vertical offset which you specify e.g. in character or graph units:
plot fuente using 0:2:xtic(1) with boxes, '' using 0:2:2 with labels offset 0, char 1
Sidenote: Adding the constant value of 0.5 to the y-value (like $2 + 0.5) doesn't work for you, because the 0.5 is in units of the y-axis, and very small compared to your yrange.

GNUplot: data labels are printed on top of each other when a multiplot is created

I have created a plot made up of four subplots; each subplot is a bar chart. Above the smaller bars I want to print how many units on the y-scale the bar represents. To do this I use 'set label', which works fine if I create individual files for the subplots, but not if I use multiplot. In this case the labels are successively printed on top of each other (i.e. those of the first subfigure also appear in the second, etc.).
Here is a truncated version of my gnuplot script:
set terminal postscript eps size 26cm,16cm font "Helvetica,18"
set out 'all_Figures.eps'
set multiplot
set multiplot layout 2,2
set bars fullwidth
set data style boxes
set boxwidth 0.5
set style fill solid 1.0 border -1
set border 3 front linetype -1 linewidth 1.000
set xtics border in scale 0,0.5 nomirror norotate offset character 0, 0, 0
set ytics border in scale -1,0 nomirror norotate offset character 0, 0, 0
set nogrid
set datafile separator ","
# ** First Plot **
set label "36" at first 2, 130 center
set label "86" at first 3, 160 center
set size .4,.3
plot 'allPDB_perc.csv' using 2:xticlabels(1) notitle
# ** Second Plot **
set size .4,.3
set label "10" at first 3, 236 center
set label "3" at first 4, 236 center
plot 'allPDB_num_dom.csv' using 2:xticlabels(1) notitle
unset multiplot
Is someone able to tell me how to clear the previous subfigure's data labels prior to generation of the current labels? Thanks a lot in advance!
Oh dear >_< I simply had to unset the labels after plotting, like so:
# ** Plot 1 **
set label ...
plot 'datafile.dat'
unset label
# ** Plot 2 **
set label ...

Resources