Is this plot typical of gnuplot? - gnuplot

I have a look at https://stats.stackexchange.com/tags/data-visualization/info and it seems to me that maybe I can find an answer here... or maybe it is off-topic here too.
Is this plot typical of gnuplot?
Source: https://arxiv.org/pdf/2003.10405.pdf

It's not the default look of gnuplot.
But gnuplot is quite customizable, and the looks depend on the capability of the output device (terminal) used and the libraries it was built with.
It is not uncommon to have your own ~/.gnuplot or a site-wide /usr/local/share/gnuplot/<version>/gnuplotrc.
From the built-in help:
When gnuplot is run, it first looks for a system-wide initialization file
gnuplotrc. The location of this file is determined when the program is built
and is reported by show loadpath. The program then looks in the user's HOME
directory for a file called .gnuplot on Unix-like systems or GNUPLOT.INI on
other systems. (OS/2 will look for it in the directory named in
the environment variable GNUPLOT; Windows will use APPDATA).
Unless you are student that has to follow your institution's style guide, I would encourage you to develop your own style(s) based on the examples you can find online and your needs.
The information and examples available on gnuplotting.org is very valuable for that purpose.

As #Roland Smith said, gnuplot is quite customizable.
To help you see how customizable it is, see below a complete example which reproduces wanted plot.
reset
set encoding utf8
# ***** TERMINAL SETTINGS *****
set terminal wxt size 800,450 font "Consolas"
# ***** GENERAL SETTINGS *****
# tics, key, and border
set tics nomirror scale 1.5
unset key
set border 7
# linestyles
set style line 1 lc "black"
set style line 2 lc "red"
# margins
set lmargin screen 0.100
set rmargin screen 0.900
set bmargin screen 0.135
# xlabel, xrange, and (m)xtics
set xlabel "Time [sec]"
set xrange [0:2.2]
set xtics 0.2 tc ls 1
set mxtics 4
# ***** CREATING SOME DATA TO PLOT *****
# Gaussian function plus some noise
f(x,a,b,c) = a*exp(-(x-b)**2/(2*c**2)) + a*0.02*rand(0)
# Storing on datablock
# First one
set table $FlowData
plot f(x, 80.0, 0.25, 0.15)
unset table
# Second one
set table $PressureData
plot f(x, 35.0, 0.75, 0.20)
unset table
# ***** THE PLOTS *****
# Turning-on the multiplot mode to place both plots
set multiplot
# ***** FIRST PLOT SETTINGS *****
set ylabel "Flow [l/min]"
set yrange [-10:120]
set mytics 4
# Fist plot itself
plot $FlowData axes x1y1 w l ls 1 lw 2
# ***** SECOND PLOT SETTINGS *****
# Remove previous customizations
unset tics
unset xlabel
unset ytics
unset ylabel
# New customizations
set border 8 ls 2
set y2label "Pressure [mbar]" tc ls 2
set y2range [-5:60]
set y2tics tc ls 2
set my2tics 4
# Labels
set label "Compliance : 15 [ml/mbar]" at 0.95,100.0 offset 0, 0
set label "Resistance : 5 [mbar/l/sec]" at 0.95,100.0 offset 0,-1
set label "PEEP : 5 [mbar]" at 0.95,100.0 offset 0,-2
set label "Inspiratory Pressure : 30 [mbar]" at 0.95,100.0 offset 0,-3
# Second plot itself
plot $PressureData axes x1y2 w l ls 2 lw 2
unset multiplot
The result:

By default font usually looks different and axis titles are centered.

Related

Gnuplot - How to make multiple plots and save each one to different files with cairolatex

I need to make a 2d plot and a 3d plot, which I want to save as .tex files, respectively labo2-mag/latex/position-x-y-over-time.tex and labo2-mag/latex/position-3d.tex. Is there anything wrong with my script ?
# General settings
set tics font ", 14"
set tmargin at screen 0.7
set key at screen 0.3, 0.8 font ",14" spacing 1.3 samplen 0.8 box opaque
# set key outside font ",14" spacing 1.3 box opaque
# Send the border to the background
set border lw 0.1 back
set xlabel '$t$ [s?]' offset 1.7;
set ylabel '$Position$ [m?]' offset -1;
# Plot once 'in the air'
# set terminal unknown
plot "labo2-mag/data/output.out" using 1:2 with points pointtype 6 lc rgb "red" title '$x(t)$', \
"" using 1:3 with points pointtype 8 lc rgb "green" title '$y(t)$', \
"" using 1:4 with points pointtype 6 lc rgb "blue" title '$z(t)$'
# pause 70
# reread
set terminal cairolatex pdf size 10cm, 10cm
set out 'labo2-mag/latex/position-x-y-over-time.tex'
MAX_Y=GPVAL_Y_MAX
MIN_Y=GPVAL_Y_MIN
MAX_X=GPVAL_X_MAX
MIN_X=GPVAL_X_MIN
set xrange [MIN_X-(MAX_X-MIN_X)*0.1:MAX_X+(MAX_X-MIN_X)*0.01]
set yrange [MIN_Y-(MAX_Y-MIN_Y)*0.05:MAX_Y+(MAX_Y-MIN_Y)*0.05]
replot
# reset terminal
splot "labo2-mag/data/output.out" using 2:3:4 with points pointtype 6 lc rgb "red" title '$pos(t)$'
set terminal cairolatex pdf size 10cm, 10cm
set out 'labo2-mag/latex/position-3d.tex'
replot
Your splot command is issued while the first terminal is still active and writing to the first output file. You need to change the terminal and output before doing a new plot. The minimum would be to issue unset output after each of your replot statements.
You might want or need to also set a new intermediate terminal type together with the unset output. I don't understand the "in the air" comment in the script. Do you mean you don't actually want to plot it? You want to view it interactively before plotting to a file? Otherwise maybe set terminal dumb? If it is relevant, please clarify.

Gnuplot use two different scales in the same axis

I am trying to create a graphic using gnuplot 5.0 with two scales in the same x axis. I have managed to create one using the multiplot option with the following code:
reset
set terminal pngcairo
set output "test.png"
unset key
set ylabel "Temperature (C)"
set ytics nomirror
set yrange[0:7]
set multiplot layout 1,2
set xrange [0:5.99] #Avoid plotting the last xtics in the first graphic
set xlabel "Heating time (minutes)"
set rmargin at screen 0.7
plot x
set xrange [0:4]
set xlabel "Seconds after stop"
set rmargin
set lmargin at screen 0.7
set xtics 1
unset ylabel
unset ytics
set y2tics nomirror
set format y2 ''
f(x) = a * exp (-x*b)
a=6
b=1
plot f(x)
With this result:
I want to generate several images like this one and add them in a multiplot arrangement, but I am not sure if using nested multiplots will be easy. Is there an easier way to obtain each of the images without using multiplot, like splitting the xaxis in two components?
Thanks in advance.
Just in case this still might be of interest to the OP or somebody else... You don't explicitly write whether you want to plot functions or data from a datafile. In your examples you use functions.
You can do something without "nested" multiplots, which would certainly be possible as well, but probably getting a bit confusing.
So, maybe the following might be easier. You basically set the xtics "manually". In order to avoid typing the same code several times you can use macros (check help macros).
Code:
### multiplot graph with different x-axis scales
reset session
# define functions
Temperature(x) = x<t0 ? x*a/t0 : a*exp(-(x-t0)*b)
myColor(col) = column(col)<t0 ? 0xff0000 : 0x0000ff
myTic(x,t) = sprintf("%g", x<=t ? x : x-t)
# define macro
myPlot = "\
set xrange[0:t0+t1]; \
set arrow 1 from first t0, graph 0 to first t0, graph 1 nohead; \
set label 1 'heating' center at first t0/2., graph 0 offset 0,-2; \
set label 2 'cooling' center at first (t0+t1/2.), graph 0 offset 0,-2; \
set xtics (); \
do for [i=0:int(t0/dt1)] { set xtics add (myTic(i*dt1,t0) i*dt1) }; \
do for [i=0:int(t1/dt2)] { set xtics add (myTic(i*dt2,t1) i*dt2+t0) }; \
plot '+' u 1:(Temperature($1)):(myColor(1)) w l lc rgb var "
set samples 200
set key noautotitle
set bmargin 3
set ylabel "Temperature"
set grid x,y
set multiplot layout 2,2
t0=6; t1=4; dt1=1; dt2=1; a=6; b=1
#myPlot
t0=4; t1=10; dt1=1; dt2=2; a=4; b=0.5
#myPlot
t0=20; t1=30; dt1=5; dt2=10; a=2; b=0.1
#myPlot
t0=4; t1=4; dt1=1; dt2=1; a=10; b=1
#myPlot
unset multiplot
### end of code
Result:

Forcing same palette on multiple pm3d plots in gnuplot

Following the great info on splot pm3d I want to create two color / contour plots with same color range.
Below code creates two plots. The way the data comes in the first data set has z-data 2.0 to 5.5. The second 1.5 to 5.5. I would like both plots to use and show the same color key scale for both for better comparison. (i.e. 2 to 6)
I tried using zrange but it did not work.
#- BASE ---------------------------------------------
reset
#set zrange [2:6]
set contour
unset surface
set cntrparam levels incr 2.0,0.5,8.0
set view map
set xrange [0:2184]
set yrange [0:1472]
set dgrid3d 100,100,4
set table "ap130_base_contour.txt"
splot 'ap130_base.dat' using 11:12:14
unset table
unset contour
set surface
set table "ap130_base_dgrid.txt"
splot 'ap130_base.dat' using 11:12:14
unset table
reset
set pm3d map
unset key
set palette defined (0 '#352a87', 1 '#0363e1',2 '#1485d4', 3 '#06a7c6', 4 '#38b99e', 5 '#92bf73', 6 '#d9ba56', 7 '#fcce2e', 8 '#f9fb0e')
set autoscale fix
set grid
set terminal png size 2184,1472 enhanced font "Helvetica,20"
set output 'ap130_base.png'
splot 'ap130_base_dgrid.txt' w pm3d, 'ap130_base_contour.txt' w l lc rgb "black"
set output
set terminal X11
#- TSFF ---------------------------------------------
reset
#set zrange [2:6]
set contour
unset surface
set cntrparam levels incr 2.0,0.5,8.0
set view map
set xrange [0:2184]
set yrange [0:1472]
set dgrid3d 100,100,4
set table "ap130_tsff_contour.txt"
splot 'ap130_tsff.dat' using 11:12:14
unset table
unset contour
set surface
set table "ap130_tsff_dgrid.txt"
splot 'ap130_tsff.dat' using 11:12:14
unset table
reset
set pm3d map
unset key
set palette defined (0 '#352a87', 1 '#0363e1',2 '#1485d4', 3 '#06a7c6', 4 '#38b99e', 5 '#92bf73', 6 '#d9ba56', 7 '#fcce2e', 8 '#f9fb0e')
set autoscale fix
set grid
set terminal png size 2184,1472 enhanced font "Helvetica,20"
set output 'ap130_tsff.png'
splot 'ap130_tsff_dgrid.txt' w pm3d, 'ap130_tsff_contour.txt' w l lc rgb "black"
set output
set terminal X11
Note the color scale i the first plot from 2.0 to 5.5
In the second plot from 1.5 to 5.5
I would like both plots to have a color scale from i.e. 1 to 6.
Your input is appreciated.
Gert
Try
set zrange[2:6]
set cbrange[2:6]
It should do the trick.

How do I plot multiple Y axis for a single X axis in a single Gnuplot window?

I am using the 32-bit version of GNUPlot in a Window 7 "Professional" OS Environment (...sadly!) and I want to do a "stack-plot" of boxes using ONLY ONE x-axis for ALL which is "TIME" in the format of a series of "Dates".
ALL of the GNUPlot Code works but, each of the plots uses its own individual x-axis which consumes a lot of graphing real estate.
I also need to be able to have variable y-axis scales for each of the stacked-plots...
Here is the "labeled" (CSV) data file:
Date,Time,Weight(kg),Height(cm),BMI,BP Max.(mmHg),BP Min.(mmHg),P/min,% Fat 09/09/2015,13:16:00,77.4,171,26.5,121,73,75,22.5 16/07/2015,09:14:34,76.9,170,26.6,111,70,76,23.5 26/06/2015,18:14:48,76.9,170,26.6,123,72,78,23.2 19/06/2015,08:45:42,77,172,26,96,60,89,22.1 15/06/2015,12:29:48,77.7,170,26.9,117,73,87,23.6 15/06/2015,12:15:58,77.8,170,26.9,127,76,77,23.7 15/06/2015,12:11:05,77.7,171,26.6,118,74,83,22.8 23/03/2015,16:39:55,78.6,170,27.2,119,72,78,24 20/03/2015,09:07:30,77.6,169,27.2,138,74,77,24.1 09/01/2015,14:30:00,79.2,170,27.4,114,71,75,24.1 07/10/2014,16:06:00,78.4,171,26.8,119,73,108,24.8 07/10/2014,16:08:00,78.4,170,27.1,109,72,75,25.1 15/09/2014,08:18:23,76.9,171,26.3,116,69,102,24.8 15/09/2014,09:20:27,76.7,172,25.9,132,76,91,21 04/09/2014,12:05:00,75.6,169,26.5,115,71,96,25.4 01/04/2014,11:18:00,76.2,171,26,115,69,70,22.9 19/03/2014,09:48:23,75.3,171,25.8,113,69,55,22.1 14/03/2014,10:39:29,75.6,170,26.2,108,69,78,22.5 05/03/2014,16:45:00,75.9,170,26.3,129,73,84,23.3 09/05/2013,17:31:00,74.5,171,25.5,135,75,92,21
And here is the "current" GNUPlot Code that I am using to generate the 5 stacked plots:
reset
set terminal windows size 1325, 625
set multiplot layout 5, 1 title "Individual Employee Biometric Data vs. Time"
set xlabel "DATE"
set timestamp
set key outside
set key center right
set pointsize 1.0
set grid lw 1
set timefmt "%d/%m/%Y"
set xdata time
set format x "%d/%m/%Y"
set xrange [ "09/05/2013\t0000" : "09/09/2015\t0000" ] noreverse nowriteback
set datafile sep ','
set arrow from 10.0,0 to 10.0, 0.5 lw 3
set label ' ' at 10.2,0.03
set label '(C) 2015' at 2050.0,-0.85
set border lw 2
set yrange [73.0:80.0]
set ylabel "(kg)"
plot 'K8.dat' using 1:3 title "BODY\nWEIGHT" with linespoints lw 2 lt rgb 'red'
set yrange [25.0:30.0]
set ylabel "kg/m^2"
plot 'K8.dat' using 1:5 title "BODY\nMASS\nINDEX" with linespoints lw 2 lt rgb 'green'
set yrange [50.0:150.0]
set ylabel "(mmHg)"
plot 'K8.dat' using 1:6 title "SYS" with linespoints lw 2 lt rgb 'blue', \ 'K8.dat' using 1:7 title "DIAS" with linespoints lw 2 lt rgb 'coral'
set yrange [40.0:120.0]
set ylabel "(bpm)"
plot 'K8.dat' using 1:8 title "HEART\nRATE" with linespoints lw 2 lt rgb 'purple'
set xlabel "DATE"
set yrange [15.0:30.0]
set ylabel "(%)"
plot 'K8.dat' using 1:9 title "BODY\nFAT" with linespoints lw 2 lt rgb 'orange'
PS - This code is from a previous GNUPlot routine so "excuse" the '#" commenting-out...
You can use multiplot to stack several plots on top of each other. You just have to switch off the plot borders appropriately for each, see help set border, and unset the abscissa xtics for all but the lowermost plot.
set multiplot
set origin 0.1, 0.1
set size 0.9,0.3
set xrange [a:b]
plot "first"
set origin 0.1,0.4
unset xtics
set border 2 # only plot left border
plot "second"
set origin 0.1,0.7
plot "third"
unset multi
Crucial is fixing the xrange for all plots, because after switching off the xtics for the following plots, you can't see if it is actually identical.
(too long for a comment)
Ok, I get what you mean by stacked plots now. To my knowledge, having several y-axes (more than 2) above a single x axis is not possible.
What you COULD however do is try to fake more than 2 axes by plotting all data in the roughly 30...150 range on the y(1)-axis, and all data in the 15...30 range on the y2axis. However, the lines would be all kind of overlapping and not as cleanly separated.
Another alternative would be to first normalize all data into an e.g. 0...10 range by subtracting the min value and dividing by max-min, then stacking these on top of each other by adding 0 for the first line, 10 for the second, and so on. However, you would then have to add hand-made y-axis tics (which is possible but somewhat bothersome).
Actually, here is a working template for the fancier solution I outlined above (implemented for three data sets, but can be extended to basically arbitrarily many)
reset
set datafile separator ","
inputfile = 'data0.txt'
stats inputfile using 3 name 'STATS_WEIGHT'
STATS_WEIGHT_range = STATS_WEIGHT_max - STATS_WEIGHT_min
stats inputfile using 4 name 'STATS_HEIGHT'
STATS_HEIGHT_range = STATS_HEIGHT_max - STATS_HEIGHT_min
stats inputfile using 9 name 'STATS_FAT'
STATS_FAT_range = STATS_FAT_max - STATS_FAT_min
# more stats for further data -- apparently needs to be BEFORE the date/time stuff
set timefmt "%d/%m/%Y"
set xdata time
set format x "%d/%m/%Y"
set xrange [ "09/05/2013\t0000" : "09/09/2015\t0000" ] noreverse nowriteback
# define the offset at which the fake y-axes start; decrease or increase offsetIncrease for spacing (effectively: blank labels) between 'graphs'
startYTicsOffset = 0
numberOfFakeYTicsPerData = 6
scalingFactor = 1.0/(numberOfFakeYTicsPerData - 1.0)
offsetIncrease = numberOfFakeYTicsPerData + 0.5
#to get rid of actual yrange numbering, set a dummy label that will be overwritten
set ytics ("dummy" 0)
#increase total actual yrange factor as needed for additional series
set yrange [0: 3 * offsetIncrease]
#add tics for weight, note that %.Xf prints the number with X decimals
do for[i=0:numberOfFakeYTicsPerData-1]{
set ytics add (sprintf("%.0f kg", STATS_WEIGHT_min + i * scalingFactor * STATS_WEIGHT_range) startYTicsOffset+i)
}
#add tics for height
startYTicsOffset = startYTicsOffset + offsetIncrease
do for[i=0:numberOfFakeYTicsPerData-1]{
set ytics add (sprintf("%.1f cm", STATS_HEIGHT_min + i * scalingFactor * STATS_HEIGHT_range) startYTicsOffset+i)
}
#add tics for fat - I couldn't figure out how to get gnuplot to print actual '%' character in sprintf directive (should be '%%' but doesn't appear to work)
startYTicsOffset = startYTicsOffset + offsetIncrease
do for[i=0:numberOfFakeYTicsPerData-1]{
set ytics add (sprintf("%.1f percent", STATS_FAT_min + i * scalingFactor * STATS_FAT_range) startYTicsOffset+i)
}
###### ... add further tics ...
plot inputfile using 1:( 0 * offsetIncrease + ($3 - STATS_WEIGHT_min)/ (STATS_WEIGHT_range * scalingFactor) ) w lp title "weight",\
inputfile using 1:( 1 * offsetIncrease + ($4 - STATS_HEIGHT_min)/ (STATS_HEIGHT_range * scalingFactor) ) w lp title "height",\
inputfile using 1:( 2 * offsetIncrease + ($9 - STATS_FAT_min) / (STATS_FAT_range * scalingFactor) ) w lp title "fat %"
### ... add further data ...
by the way: if you post or edit a question or an answer, try clicking the image icon above the editing window. It will open a little window where you can drag and drop images directly without needing a web hosting service. Like that:

Changing ytic font size in gnuplot epslatex (multiplot)

I have problems changing the font size of my ytics (xtics as well) in an epslatex gnuplot.
I tried set format y '\tiny{%g}'
It is only working for the first of the two plots.
This is my code:
set terminal epslatex
set output "w_alt_nsyB_multi.tex"
set multiplot layout 1,1
set xrange [-0.5:17]
set yrange [0:110]
set xlabel "days"
set ylabel "Survival (\\%)" offset 2.5
set key reverse
set xtics font 'Arial,4' s
et style histogram errorbars gap 2 lw 1
set style data histogram
set style fill solid 1 border lt -1
set boxwidth 0.8
plot 'w_alt_nsyB.dat' every ::::7 using 2:3:xticlabels(1) title 'w1118' lt rgb "#000000",\
'w_alt_nsyB.dat' every ::::7 using 4:5 title 'wtSYN' lt rgb "#FF0000",\
'w_alt_elav_endoG.dat' every ::::7 using 6:7 title '38085' lt rgb "#9400D3"
set origin 0.5, 0.25
set size 0.5, 0.5
set xrange [-0.5:6]
set yrange [0:110]
set xlabel "\\tiny{Time of $Mn^{2+}$ treatment}"
set ytics ('10'10,'50'50,'100'100) nomirror
unset border
set xtics nomirror
unset ylabel
unset key
plot 'w_alt_nsyB_100.dat' using 2:3:xticlabels(1) lt rgb "#000000",\
'w_alt_nsyB_100.dat' using 4:5:xticlabels(1) lt rgb "#FF0000",\
'w_alt_nsyB_100.dat' using 6:7:xticlabels(1) lt rgb "#9400D3"
unset multiplot
Can anyone help me please?
The format given in set format ... isn't applied if you give an explicit manual label like you do with
set ytics ('10'10,'50'50,'100'100)
You must either just give the locations of the labels
set format y '\tiny %g'
set ytics (10, 50, 100)
or include the font macro in every manual label
set ytics ('\tiny 10' 10, '\tiny 50' 50, '\tiny 100' 100)
Note also, that your syntax \tiny{%g} is wrong, \tiny is only a switch and doesn't take any arguments. In this case it doesn't matter, because every label is wrapped in an individual LaTeX box, but in other situations it makes a big difference. To wrap the tiny font you would usually need {\tiny %g}.
The same happens for the explicit labels which are set with xticlabel. Also here, the format from set format x doesn't apply. Instead of giving a column number to xticlabel (like xticlabel(1) in your example), you must give the complete label string including the macro:
xl(c) = sprintf('\tiny %s', strcol(c))
plot 'file.dat' using 2:3:xticlabel(xl(1))
Next time, please give a minimal example which allows others to reproduce your problem. We don't have your data files to run the script. And your problem isn't related to you specific data file, so you can as well construct an example using functions, which possibly leads you itself to the solution...

Resources