Customizing gnuplot clustered histogram x-axis labels - gnuplot

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.

Related

gnuplot: bar charts visualization

My gnuplot script plot a bar graph for 2D data either in monochrome or color format:
set term pngcairo size 800,600
set termoption noenhanced
set tics font "Helvetica,10"
#set xtics noenhanced
set ylabel "Fraction, %"
set xlabel "H-bond donor/aceptor, residue"
set yrange [0:1]
set ytics 0.1
set grid y
set key off
set boxwidth 0.9
set style fill solid 0.5
# TWO OPTIONS FOR BAR VISUALISATIONS!! NB: ADD HERE TRIGGER FROM COLOR_DATA TRIGGER
# 1 - use it with non-colored bars"
#plot "\$data" using 0:2:xtic(1) with boxes, "" using 0:2:2 with labels offset 0,1
# 2 - or use it with colored bars:
plot \$data using 0:2:3:xtic(1) with boxes lc rgb var, \
'' using 0:2:2 with labels offset 0,1
The problem when I have just one bar, one the graph it occupiers all the graph on X:
Would it be possible to set some minimum dimension for the bars to make the dimensions of a single bar similar for a situations with two bars, for instance:
My understanding is the following: if you have only one box:
maybe gnuplot tries to autoscale and the automatic boxwidth is small relative to the autorange (hence just a thin line).
if you set a certain boxwidth, autoscale with scale to the given boxwidth (hence the graph filled with the box).
you could set a fixed xrange, but then you are loosing the benefits of autoscale. Instead you can use set offets (check help offsets).
if you have more than 1 box autoscale will work.
Script:
### boxwidth with boxes style
reset session
$Data1 <<EOD
1 Abc
EOD
$Data2 <<EOD
1 Abc
2 Xyz
EOD
set style fill solid 0.3
set key out
set rmargin screen 0.7
set yrange[0:]
set ytics 0.5
set multiplot layout 4,1
plot $Data1 u 0:1:xtic(2) w boxes ti "No special settings"
set boxwidth 0.9
plot $Data1 u 0:1:xtic(2) w boxes ti "set boxwidth"
set offsets 1,1,0,0
plot $Data1 u 0:1:xtic(2) w boxes ti "set offsets"
set offsets 0,0,0,0
plot $Data2 u 0:1:xtic(2) w boxes ti "more than 1 box"
unset multiplot
### end of script
Result:

Changing bar colors on bar graphs with gnuplot

I'm using gnuplot to plot bar graphs.
Here is my resulting graph:
The question is: I want each bar to have different colors. For example: MSA-GA ACO in red and MSA-GA PACO in blue.
How do I do this?
Here are the comands I've used:
set yrange [0:14000]
set style fill solid
set boxwidth 0.7
set xtics format ""
set grid ytics
set title "Total Runtime"
set ylabel "Time (s)"
unset key
plot "data.dat" u 1:3:xtic(2) with boxes, "" u 1:3:3 with labels offset char 0,0.7
The "data.dat":
0 "MSA-GA ACO" 12726.38
1 "MSA-GA PACO" 5290.00
You can use linecolor variable with the boxes plotting style. The only thing to keep in mind is that you cannot change the color of linetype 0, so I add 1 to the value in the first column of your data file to select the color id:
set yrange [0:14000]
set style fill solid
set boxwidth 0.7
set xtics format ""
set grid ytics
set title "Total Runtime"
set ylabel "Time (s)"
unset key
set linetype 1 lc rgb "red"
set linetype 2 lc rgb "blue"
plot "data.dat" u 1:3:($1+1):xtic(2) with boxes linecolor variable

Set background of boxes in boxplot to a specific color with gnuplot

I've got the following data:
# id min 1st quart median 3rd quart max sum std-dev name
1 0.00029 0.02590 0.06331 0.12910 6.50177 1524.58705 0.13483 spec
2 1.50041 1.59762 1.67226 1.79827 13.45151 26583.69935 0.48373 schema
3 0.00206 0.01292 0.02505 0.09679 116.93156 5337.36854 2.06006 truss
And the following gnuplot script:
set terminal png enhanced background rgb 'white' size 1920,1200 font "Verdana 10"
set output "charts/summary.png"
set boxwidth 0.2 absolute
set title "Validating all data"
set xrange[0:4]
set yrange[0.00005:50]
set logscale y
set grid y
set tics scale 0
set xtics rotate by -45
set xtics nomirror
set ytics nomirror
set border 2
set style fill solid 0.25 border -1
set style data boxplot
plot "data/summary" using 1:3:2:6:5:(0.6):xticlabels(9) with candlesticks title 'Quartiles' whiskerbars, \
'' using 1:4:4:4:4:(0.6) with candlesticks lt -1 notitle
The output of which looks like:
The problem being that I can't figure out how to set the background color of the boxes in the boxplot. I can only seem to turn on and off the fill-in color by removing the set style fill solid 0.25 border -1 line.
Although the name of keyword doesn't suggest so, the linecolor seems to affect the color of the boxes, thus for example:
plot "data/summary" using 1:3:2:6:5:(0.6):xticlabels(9) with candlesticks lc rgb 'blue' title 'Quartiles' whiskerbars, \
'' using 1:4:4:4:4:(0.6) with candlesticks lt -1 notitle

Gnuplot Multiplot Individual Plot Sizes + Labels

I am currently trying to produce a decent multiplot in Gnuplot. Sadly I ran into some problems.
As the y-axis for both figures is the same I want to only label and tic it once, however I cant remove those from only the left plot.
Secondly I want to increase the width of the left plot while decreasing the one of the right.
Here is a picture of what I got so far, the code is below.
Plot so far
set term postscript eps enhanced color "Helvetica" 10
set output "dosband.eps"
set title "Bandstructure and Density of States"
#
set multiplot layout 1,2 \
margins 0.075,0.98,0.1,0.98 \
spacing 0.02,0.08 #margins: left,right,bottom,top; spacing: vertical, horizontal
set title "Bandstructure"
plot 'plotband.dat' using 1:2 with lines lt 1 lw 0.5 linecolor rgb "black" notitle
set xlabel "Density [states/eV]" #dont ask me why I have to swap the xlabels around
set ylabel "Energy [eV]"
#
set title "Density of States"
plot 'plotdos.dat' using 1:2 with lines lt 1 linecolor rgb "black" notitle
set xlabel "K-Points"
unset multiplot
Thanks in advance for any answers!
As noted by #Christoph, using explicit margins is one of the solutions. In your particular case, you could proceed as:
#dimensions are in screen units
width_left = 0.48
width_right = 0.25
eps_v = 0.12
eps_h_left = 0.1
eps_h_right = 0.05
unset key
set multiplot
set tmargin at screen 1. - eps_v
set bmargin at screen eps_v
set lmargin at screen 0.1
set rmargin at screen eps_h_left + width_left
set xr [0:1.4]
set xtics 0,0.2,1.4
set yr [-40:5]
unset ytics
set y2r [-40:5]
set y2tics in mirror
set format y2 "" #draw ticks but no tic labels
set title "Plot 1"
set xlabel "title 1"
plot 1/0
set lmargin at screen 1. - (width_right + eps_h_right)
set rmargin at screen 1. - eps_h_right
set xr [0:100]
set xtics 0,25,100
unset y2tics
set yr [-40:5]
set ytics in mirror
set mytics 1
set title "Plot 2"
set xlabel "title 2"
set ylabel "Energy [eV]"
plot 1/0
This produces:
In case the Energy [eV] label is supposed to be moved completely to the left, one can adjust the spacings/tics accordingly...

Gnuplot: Multiplot Plot Just Curve Without Axis Or Title etc

I've used the following script to generate a plot and the result is shown in the figure below. It is hard to see, but the xlabel, ylabel, title and tic numbers have actually been drawn over and over again each time a plot function was called while in multiplot. In ideas how I can avoid this and just plot the graph without anything else? If I unset the title, tics etc and then plot, then the graph does not plot in the same area as the frame and petrudes into where the left y-axis is.
#set datafile separator ' '
set samples 1000
set term tikz size 17cm,10cm dashed
set out 'MosfetClassAbPower.tex'
unset key
set border lw 2
set style fill transparent solid 0.5 noborder
set title 'MOSFET $\mathrm{I_D}$ Vs Time'
set ylabel 'Drain Current [$\mu$A]'
set xlabel 'Time [ms]'
set xrange [0:4]
set xtics 0,0.5,4
set mxtics 4
set yrange [-50:450]
set mytics 4
set rmargin 5
set label 1 '\SI{60}{\micro\ampere}' at 4.02,60
set multiplot
set grid mxtics mytics lt -1 lc rgb 'gray90'
plot NaN notitle
unset grid
set grid xtics ytics lt -1 lc rgb 'gray70'
plot NaN notitle
unset grid
plot NaN notitle
Id(x) = 347*sin(2*3.14*x) + 60
ID(x) = Id(x) >= 0 ? Id(x) : 0
plot ID(x) w filledcurves above y1=0 lc rgb 'light-blue',\
60 w lines lt 2 lw 3 lc rgb 'gray60',\
ID(x) w lines lt 1 lw 5 lc rgb 'navy'
plot NaN notitle
unset multiplot
set out
My attempt at preventing the curve from protruding over the frame.
Edit:
reset
#set term tikz size 17cm,10cm dashed standalone header '\usepackage{siunitx}'
#set out 'MosfetClassAbPower.tex'
#TSCALE = 1.0
set terminal pdfcairo dashed
set out 'MosfetClassAbPowerFixed.pdf'
TSCALE = 20.0 # use this value for e.g. pdfcairo or cairolatex
TITLE = 'MOSFET $I_D$ Vs Time'
YLABEL = 'Drain Current (in \si{\uA})'
XLABEL = 'Time (in \si{\ms})'
set style fill transparent solid 0.5 noborder
set xrange [0:4]
set xtics 0,0.5,4
set mxtics 4
set yrange [-50:450]
set mytics 4
set rmargin 5
LABEL = '\SI{60}{\uA}'
set label 1 LABEL at graph 1.01, first 60
unset key
set samples 1000
set multiplot
set title TITLE
set ylabel YLABEL
set xlabel XLABEL
unset border
set tics scale 0,0.001
set grid mxtics mytics lt -1 lc rgb 'gray90'
plot NaN
unset grid
# keep the current margins for all following plots
set lmargin at screen TSCALE*GPVAL_TERM_XMIN/(1.0*GPVAL_TERM_XSIZE)
set rmargin at screen TSCALE*GPVAL_TERM_XMAX/(1.0*GPVAL_TERM_XSIZE)
set tmargin at screen TSCALE*GPVAL_TERM_YMAX/(1.0*GPVAL_TERM_YSIZE)
set bmargin at screen TSCALE*GPVAL_TERM_YMIN/(1.0*GPVAL_TERM_YSIZE)
# unset almost everything
unset border
unset label
unset xlabel
unset ylabel
set format x ''
set format y ''
unset title
set grid xtics ytics lt -1 lc rgb 'gray70'
plot NaN
unset grid
Id(x) = 347*sin(2*3.14*x) + 60
ID(x) = Id(x) >= 0 ? Id(x) : 0
plot ID(x) w filledcurves above y1=0 lc rgb 'light-blue',\
60 w lines lt 2 lw 3 lc rgb 'gray60',\
ID(x) w lines lt 1 lw 5 lc rgb 'navy'
# overdraw borders on left, right, top, bottom
set object 1 rectangle from screen 0, screen 0 to graph 0, screen 1 back \
fillstyle solid noborder
set object 2 rectangle from graph 1, screen 0 to screen 1, screen 1 back \
fillstyle solid noborder
set object 3 rectangle from screen 0, graph 1 to screen 1, screen 1 back \
fillstyle solid noborder
set object 4 rectangle from screen 0, screen 0 to screen 1, graph 0 back \
fillstyle solid noborder
plot NaN
unset object 1
unset object 2
unset object 3
unset object 4
set title TITLE
set ylabel YLABEL
set xlabel XLABEL
set label 1 LABEL at graph 1.01, first 60
set format x
set format y
set tics scale 1,0.5 front
set border
set border lw 2
plot NaN
unset multiplot
set out
It is not possible, to set different layers for all plot elements and stack them arbitrarily. You must play around with set and unset for the various elements.
In order to have the tics drawn only once, I set their scale to 0 (this works for the major tics, but not for the minor tics, where I use 0.001).
I fix the margins after the minor grid lines are drawn (see Gnuplot: Store plot area dimensions for later use).
Unset everything, which shouldn't be drawn again (label, object, arrow, tics labels etc). Do not unset tics, because we want to drawn them last, so just use set format x '' to draw the tics, but not their labels.
Set the tics to their default scale, and set the border before the last plot, to have them drawn above the grid lines and above the plot.
reset
set term tikz size 17cm,10cm dashed standalone header '\usepackage{siunitx}'
set out 'MosfetClassAbPower.tex'
TSCALE = 1.0
# set terminal pdfcairo
# TSCALE = 20.0 # use this value for e.g. pdfcairo or cairolatex
set style fill transparent solid 0.5 noborder
set title 'MOSFET $I_D$ Vs Time'
set ylabel 'Drain Current (in \si{\uA})'
set xlabel 'Time (in \si{\ms})'
set xrange [0:4]
set xtics 0,0.5,4
set mxtics 4
set yrange [-50:450]
set mytics 4
set rmargin 5
set label 1 '\SI{60}{\uA}' at graph 1.01, first 60
unset key
set samples 1000
set multiplot
unset border
set tics scale 0,0.001
set grid mxtics mytics lt -1 lc rgb 'gray90'
plot NaN
unset grid
# keep the current margins for all following plots
set lmargin at screen TSCALE*GPVAL_TERM_XMIN/(1.0*GPVAL_TERM_XSIZE)
set rmargin at screen TSCALE*GPVAL_TERM_XMAX/(1.0*GPVAL_TERM_XSIZE)
set tmargin at screen TSCALE*GPVAL_TERM_YMAX/(1.0*GPVAL_TERM_YSIZE)
set bmargin at screen TSCALE*GPVAL_TERM_YMIN/(1.0*GPVAL_TERM_YSIZE)
# unset almost everything
unset border
unset label
unset xlabel
unset ylabel
set format x ''
set format y ''
unset title
set grid xtics ytics lt -1 lc rgb 'gray70'
plot NaN
unset grid
set tics scale 1,0.5 front
set border
set border lw 2
Id(x) = 347*sin(2*3.14*x) + 60
ID(x) = Id(x) >= 0 ? Id(x) : 0
plot ID(x) w filledcurves above y1=0 lc rgb 'light-blue',\
60 w lines lt 2 lw 3 lc rgb 'gray60',\
ID(x) w lines lt 1 lw 5 lc rgb 'navy'
unset multiplot
set out
Result:
Now the ordering is:
minor grid lines
major grid lines
curve
border, tics
Note, that I made some other tiny changes: You can use e.g. graph coordinates to set a label. And some tweaking of the label text.
EDIT:
Cairolatex or epslatex
The proceeding described above works well for any terminal which processes text and graphics together, but not for terminals like cairolatex and epslatex which also in multiplot mode know only two text layer:
front layer, contains all text placed with front keyword.
graphics, contains all graphical elements of all plot commands (also in multiplot mode).
back layer, contains all text placed with back keyword.
This may become a problem, when one wants to cover parts of the graphic (protruding lines) with a white object, but cannot put e.g. the xlabel to the front. Here is an example, which works also with cairolatex:
reset
set terminal cairolatex pdf dashed color standalone header "\\usepackage{siunitx}" size 17cm,10cm
set output 'MosfetClassAbPowerFixed.tex'
TITLE = 'MOSFET $I_D$ Vs Time'
YLABEL = 'Drain Current (in \si{\uA})'
XLABEL = 'Time (in \si{\ms})'
set style fill transparent solid 0.5 noborder
set xrange [0:4]
set xtics 0,0.5,4
set mxtics 4
set yrange [-50:450]
set mytics 4
RMARGIN=0.92
LMARGIN=0.1
set rmargin at screen RMARGIN
set lmargin at screen LMARGIN
set tmargin at screen 0.91
set bmargin at screen 0.11
unset key
set samples 1000
set multiplot
# first plot the minor grid lines
unset border
set tics scale 0,0.001 format ''
set grid mxtics mytics lt -1 lc rgb 'gray90'
plot NaN
# now plot the major grid lines
unset grid
set grid xtics ytics lt -1 lc rgb 'gray70'
plot NaN
unset grid
# plot the actual curve
# overdraw borders on left and right
set object rectangle from graph -0.005, graph 0 to screen LMARGIN, graph 1 front \
fillstyle solid noborder
set object rectangle from screen RMARGIN, graph 0 to graph 1.005, graph 1 front \
fillstyle solid noborder
Id(x) = 347*sin(2*3.14*x) + 60
ID(x) = Id(x) >= 0 ? Id(x) : 0
plot ID(x) w filledcurves above y1=0 lc rgb 'light-blue',\
60 w lines lt 2 lw 3 lc rgb 'gray60',\
ID(x) w lines lt 1 lw 5 lc rgb 'navy'
unset object
# plot all tics and labels
LABEL = '\SI{60}{\uA}'
set label 1 LABEL at graph 1.01, first 60 front
set title TITLE
set ylabel YLABEL
set xlabel XLABEL
set tics scale 1,0.5 format
set border
set border lw 2
plot NaN
unset multiplot
set out
Because of the only three layer, I put thin white rectangles between the plot border and the tic labels. To have the objects drawn outside the plotting area, one needs to use at least one coordinate value in screen coordinates, otherwise they are clipped.
As opposed the the first example, I used fixed margins for the whole plot, which I prefer.
This gives:

Resources