Mr data file is
# test.dat
# Sample No. Phenol Red Neutral Red Bromophenol Blue Bromocresol Green Mixed Indicator
1 80 69 223 222 130
2 89 62 321 267 160
3 92 67 248 276 147
Gnuplot code is
#
#
###
reset session
###
set terminal postscript eps enhanced colour font 'Times-Roman,12' size 6in,4in
set output "test.eps"
#------------------------------------------------------------------------------
set style line 1 lt 4 lw 1 lc rgb "#4169E1"
set style line 2 lt 4 lw 1 lc rgb "#2E8B57"
set style line 3 lt 5 lw 1 lc rgb "#FF4500"
set style line 4 lt 4 lw 1 lc rgb "#FAD02C"
set style line 5 lt 4 lw 1 lc rgb "#FF0080"
#------------------------------------------------------------------------------
set xtics out scale 1.5
set ytics out scale 1.5
set ytics nomirror
set yrange [0:350]
set key off
set tics font ", 16"
set xlabel "Sample No. " font ",16"
set ylabel "Moisture Content ({/Symbol \155}g of H_{2}O/g of melt)" font ",16"
set key samplen 2 spacing 1.65 font ",14" width -1.0
set key inside left horizontal
set style fill solid border
set style histogram clustered gap 1 title textcolor lt -1
# ----------------------------------------
set rmargin screen 0.9
set lmargin screen 0.1
set bmargin screen 0.4
# ----------------------------------------
set style data histogram
plot \
newhistogram "Direct titration", \
'test.dat' using 2:xtic(1) ls 4 axes x1y1 title "Phenol Red", \
'' u 3 ls 5 axes x1y1 title "Neutral Red", \
newhistogram "Back-titration", \
'test.dat.dat' using 4:xtic(1) ls 1 axes x1y1 title "Bromophenol Blue", \
'' u 5 ls 2 axes x1y1 title "Bromocresol Green", \
'' u 6 ls 3 axes x1y1 title "Mixed Indicator"
# ----------------------------------------
##
Script works fine. I would like to provide more spacing between the tick labels (1,2,3) and the sub-title (Direct titration and Back-titration) as well as spacing between the sub-titles and axis title. How can it be done?
set xlabel offset 0, -1 will shift both the subtitles and the axis title downward by one character height.
set xlabel "\nTEXT" will create a two-line axis label and place TEXT on the second line.
Modifying your xlabel command to be
set xlabel "\nSample No. " font ",16" offset 0,-1
will make both those changes.
I do not want to change my data files that come with the first column containing the time values. Then I formatted it on gnuplot to show only the hour and minute. But it is a bit ugly to start the time from 8:00. I would like to start it from 0 and keep the values at the same pace of the data file. I was trying to use a constant like this example shows How do I make a plot in gnuplot with the lowest value automatically subtracted from the y data? but it is not working.
Here are my source and the plot.
#!/usr/bin/gnuplot
# set grid
set key outside bottom center horizontal
set key font ",19"
set style line 1 lc rgb '#E02F44' lt 1 lw 1 ps 0.5 pt 7 # input throughput
set style line 2 lc rgb '#FF780A' lt 1 lw 1 ps 0.5 pt 1 # output throughput
set style line 3 lc rgb '#56A64B' lt 1 lw 1 ps 0.5 pt 2 # average processing latency
set style line 4 lc rgb '#000000' lt 1 lw 1 ps 0.5 pt 3 # 99th percentile processing latency
set style arrow 1 heads ls 4
set style arrow 2 head ls 4
set terminal pdf
set pointintervalbox 0
set datafile separator ','
set output "Cost-20K-ThroughputVsLatency.pdf"
#set title ""
set xlabel "time (minutes)" font ",17" offset 0,1,0
set xtics font ",8" offset 0,0.5,0
set xdata time # tells gnuplot the x axis is time data
set timefmt "%Y-%m-%d %H:%M:%S" # specify our time string format
set format x "%H:%M" # otherwise it will show only MM:SS
set xrange ["2020-05-07 08:05:00":"2020-05-07 09:50:00"]
set ylabel "Throughput (K rec/sec)" font ",18" offset 0,0,0
set yrange [0:7]
set ytics font ",20"
#set y2label "processing latency (seconds)" font ",18" offset -1.5,0,0
set y2range [0:25]
set ytics nomirror
set y2tics 0, 5 font ",17"
plot "throughput-vs-latency-20K.csv" using 1:(column(2)/1000) title "IN throughput" with linespoints ls 1 axis x1y1 \
, "throughput-vs-latency-20K.csv" using 1:(column(10)/1000) title "OUT throughput" with linespoints ls 2 axis x1y1 \
, "throughput-vs-latency-20K.csv" using 1:(column(18)/1000) title "avg. latency" with linespoints ls 3 axis x1y2 \
, "throughput-vs-latency-20K.csv" using 1:(column(26)/1000) title "99th latency" with linespoints ls 4 axis x1y2
UPDATE
I changed my script like you said #theozh but I am still not getting the x axis starting from 0.
set key bottom right
set key font ",11"
set style line 1 lc rgb '#E02F44' lt 1 lw 1 ps 0.5 pt 7 # input throughput
set style line 2 lc rgb '#FF780A' lt 1 lw 1 ps 0.5 pt 1 # output throughput
set style line 3 lc rgb '#56A64B' lt 1 lw 1 ps 0.5 pt 2 # average processing latency
set style line 4 lc rgb '#000000' lt 1 lw 1 ps 0.5 pt 3 # 99th percentile processing latency
set style arrow 1 heads ls 4
set term pdfcairo size 5.0in,2.5in
set pointintervalbox 0
set datafile separator ','
set tmargin 1.5
set border 1+2+8
set xtics nomirror
set output "throughput-latency-increasingK-TaxiRideNYC-50Kpersec.pdf"
myTimeFmt = "%Y-%m-%d %H:%M:%S"
set xlabel "time (minutes)" font ",9" offset 0,1.5,0
set xtics font ",8" #rotate by 45 right
set ylabel "Throughput (K rec/sec)" font ",10" offset 2,0,0
set yrange [0:3.5]
set y2label "processing latency (seconds)" font ",10" offset -2,0,0
set y2range [0:14]
set ytics nomirror
set y2tics 0, 2
set xdata time # tells gnuplot the x axis is time data
set format x "%M" time
plot t=0 "throughput-latency-increasing.csv" u (t==0?(t0=timecolumn(1,myTimeFmt),t=1):NaN, timecolumn(1,myTimeFmt)-t0):(column(2)/1000) title "IN throughput" with linespoints ls 1 axis x1y1 \
, t=0 "throughput-latency-increasing.csv" u (t==0?(t0=timecolumn(1,myTimeFmt),t=1):NaN, timecolumn(1,myTimeFmt)-t0):(column(18)/1000) title "avg. latency" with linespoints ls 3 axis x1y2 \
, 4/0 t "# of tuples pre-aggregating" with vectors arrowstyle 1
values are here:
"Time","pre_aggregate-outPool[0]-avg","pre_aggregate-outPool[1]-avg","pre_aggregate-outPool[2]-avg","pre_aggregate-outPool[3]-avg","pre_aggregate-outPool[4]-avg","pre_aggregate-outPool[5]-avg","pre_aggregate-outPool[6]-avg","pre_aggregate-outPool[7]-avg","pre_aggregate-outPool[0]-99","pre_aggregate-outPool[1]-99","pre_aggregate-outPool[2]-99","pre_aggregate-outPool[3]-99","pre_aggregate-outPool[4]-99","pre_aggregate-outPool[5]-99","pre_aggregate-outPool[6]-99","pre_aggregate-outPool[7]-99","pre_aggregate[0]-param","pre_aggregate[1]-param","pre_aggregate[2]-param","pre_aggregate[3]-param","pre_aggregate[4]-param","pre_aggregate[5]-param","pre_aggregate[6]-param","pre_aggregate[7]-param"
"2020-04-27 10:22:45",33.33333432674408,33.33333432674408,33.33333432674408,33.33333432674408,33.33333432674408,33.33333432674408,33.33333432674408,33.33333432674408,33,70,75,79,33,41,62,75,50000,50000,50000,50000,50000,50000,50000,50000
"2020-04-27 10:23:00",33.33333432674408,33.33333432674408,33.33333432674408,33.33333432674408,33.33333432674408,33.33333432674408,33.33333432674408,33.33333432674408,33,33,75,79,33,33,33,37,50000,50000,50000,50000,50000,50000,50000,50000
"2020-04-27 10:23:15",33.33333432674408,33.33333432674408,33.33333432674408,33.33333432674408,33.33333432674408,33.33333432674408,33.33333432674408,33.33333432674408,33,33,33,33,33,33,33,33,50000,50000,50000,50000,50000,50000,50000,50000
"2020-04-27 10:23:30",33.33333432674408,33.33333432674408,33.33333432674408,33.33333432674408,33.33333432674408,33.33333432674408,33.33333432674408,33.33333432674408,62,66,50,62,66,45,50,66,50000,50000,50000,50000,50000,50000,50000,50000
"2020-04-27 10:23:45",33.33333432674408,33.33333432674408,33.33333432674408,33.33333432674408,33.33333432674408,33.33333432674408,33.33333432674408,33.33333432674408,62,66,50,62,66,45,50,66,50000,50000,50000,50000,50000,50000,50000,50000
"2020-04-27 10:24:00",33.33333432674408,33.33333432674408,33.33333432674408,33.33333432674408,33.33333432674408,33.33333432674408,33.33333432674408,33.33333432674408,33,33,33,33,33,33,33,33,50000,50000,50000,50000,50000,50000,50000,50000
The following example uses the newer gnuplot date time syntax (see help timecolumn), e.g. timecolumn(1,myTimeFmt) and set format x "%H:%M" time.
In order to normalize your time series to the first data point you have to store this time into a variable, e.g. t0 which you can "re-use" in successive plot commands from the same datafile.
Note the different time format for the x axis: "%H:%M" for day time and "%tH:%tM" for hours exceeding 24 hours or minutes exceeding 60 minutes, see help time_specifiers.
Edit:
for better readability of the plot command, I "outsourced" the normalization into a function Normalize(). But note that t=0 is still required at the beginning of the plot command.
in case you have some (uncommented) header lines, you need to skip them via skip <number of header lines>.
Code:
### normalize time data relative to start time
reset session
myTimeFmt = "%Y-%m-%d %H:%M:%S"
# create some test data
set table $Data
plot '+' u (strftime(myTimeFmt,time(0) + $1*3600*2)):(cos($1)) w table
unset table
# function to normalize time column to first value
Normalize(c) = (t==0?(t0=timecolumn(c,myTimeFmt),t=1):NaN, timecolumn(c,myTimeFmt)-t0)
# in case there are uncommented header lines skip them
SkipHeaderLines = 0
set multiplot layout 2,1
set format x "%Y\n%m-%d\n%H:%M" time
plot $Data u (timecolumn(1,myTimeFmt)):3 skip SkipHeaderLines w l ti "absolute time"
set format x "%tH:%tM" time
plot t=0 $Data u (Normalize(1)):3 skip SkipHeaderLines w l ti "relative time"
unset multiplot
### end of code
Result:
I'm programming a graph with axes (y "%" and x "date") and when less than 7 records have not shown well
These are the files
data.csv:
20-04-2016 96.8 95.8 100
21-04-2016 97.07 97.99 100
22-04-2016 98.05 99.5 100
23-04-2016 98.64 97.88 100
24-04-2016 98.96 98.99 100
25-04-2016 98.68 98.11 100
graph
reset
set terminal png size 1200,500
#set xlabel "Time (days)"
set xdata time
set timefmt "%d-%m-%Y"
set ylabel "Total Petitions (%)"
set yrange [95:100]
set title "Akamai"
set key reverse Left outside
set grid
set style data linespoints
plot "datos.csv" using 1:2 title "One (%)", \
"" using 1:3 title "Two (%)", \
"" using 1:4 title "Ideal (%)"
He shows me this
As shown, the dates are repeated, and I want one date per record appears.
I also like to put the date
%d-%m\n%Y
This is solved if I put 7 or more records
And this happens if I put the full date but the description of the axis x
It could put the date vertically?
Thank you very much for your help
Use set format x;
set terminal pngcairo enhanced color dashed \
rounded size 1200,500
set title "Akamai"
set xlabel "date"
set xdata time
set timefmt "%d-%m-%Y"
set format x "%d/%m\n%Y"
set xtics 86400
set nomxtics
set ylabel "Total Petitions (%)"
set yrange [95:100]
set style data linespoints
set grid
set key right bottom
set output 'user1847844.png'
plot "datos.csv" using 1:2 title "One (%)", \
"" using 1:3 title "Two (%)", \
"" using 1:4 title "Ideal (%)"
Internally, gnuplot converts datetimes to seconds. So the line set xtics 86400 basically says to make one tick per day since one day has 24*60*60 = 86400 seconds. The set nomxtics tells gnuplot to not show minor tick marks on the x-axis.
This gives:
If you want to rotate the label, use:
set format x "%d/%m/%Y"
set xtics rotate 86400
That should format the dates as a single line and rotate the labels by 90 degrees.
Update:
Note that I'm using the pngcairo terminal. This is based on the cairo graphics library. This is designed to give consistent output on all output media. But gnuplot must be compiled with cairo support for this to work.
In general, I prefer the pdfcairo terminal. This produces PDF output which can be scaled without giving pixellation effects.
Update 2:
To get consistency in my graphs, I've defined certain styles in my gnuplotrc, which I use in my graphs. The contents of my gnuplotrc are shown below.
set encoding utf8
# See https://github.com/Gnuplotting/gnuplot-palettes
# Line styles (colorbrewer Set1)
set style line 1 lc rgb '#E41A1C' pt 1 ps 1 lt 1 lw 2 # red
set style line 2 lc rgb '#377EB8' pt 6 ps 1 lt 1 lw 2 # blue
set style line 3 lc rgb '#4DAF4A' pt 2 ps 1 lt 1 lw 2 # green
set style line 4 lc rgb '#984EA3' pt 3 ps 1 lt 1 lw 2 # purple
set style line 5 lc rgb '#FF7F00' pt 4 ps 1 lt 1 lw 2 # orange
set style line 6 lc rgb '#FFFF33' pt 5 ps 1 lt 1 lw 2 # yellow
set style line 7 lc rgb '#A65628' pt 7 ps 1 lt 1 lw 2 # brown
set style line 8 lc rgb '#F781BF' pt 8 ps 1 lt 1 lw 2 # pink
# Palette
set palette maxcolors 8
set palette defined ( 0 '#E41A1C', 1 '#377EB8', 2 '#4DAF4A', 3 '#984EA3',\
4 '#FF7F00', 5 '#FFFF33', 6 '#A65628', 7 '#F781BF' )
# Standard border
set style line 11 lc rgb '#808080' lt 1 lw 3
set border 0 back ls 11
set tics out nomirror
# Standard grid
set style line 12 lc rgb '#808080' lt 0 lw 1
set grid back ls 12
unset grid
And I use a pdfcairo terminal as standard, like this.
set terminal pdfcairo enhanced color dashed font "Alegreya, 14" \
rounded size 16 cm, 9.6 cm
The font used is an example. For graphs in reports I tend to use the same font as the body text.
The plot command uses the defined styles.
plot "user1847844.d" using 1:2 ls 1 title "One (%)", \
"" using 1:3 ls 2 title "Two (%)", \
"" using 1:4 ls 3 title "Ideal (%)"
This produces a figure looking like this.
Note: Since StackOverflow doesn't accept PDF images, I converted it to a PNG using ImageMagick.
convert -density 300 <input.pdf> -quality 100 -sharpen 0x1.0 <output.png>
I want to set the background of data labels to white! The considered plot is a data plot of the following data (gnuDC.dat):
4 1570.96 1571
8 770.63 771
12 530.33 530
16 385.13 385
24 261.87 262
48 137.71 138
96 81.42 81
The plot command reads:
plot "gnuDC.dat" using 1:2 title "DC: GNU Fortran 4.7.2 + Open MPI 1.6.3" w p ls 1, \
"gnuDC.dat" using 1:2:3 with labels center offset 2.,0.7 font "Helvetica,14" tc ls 4 notitle, \
"gnuDC.dat" using 1:3 notitle smooth csplines ls 14
Which gives me:
It looks ok but think one could read the lables better when the would have an white background. Is there an easy way to add the white background for all labels at once?
Here is the whole print file:
set terminal postscript eps size 14cm,10cm enhanced color \
font 'Helvetica,18' linewidth 2
set output 'test.eps'
# Line style for axes
set style line 80 lt 0
set style line 80 lt rgb "#808080"
# Line style for grid
set style line 81 lt 3 # dashed
set style line 81 lt rgb "#808080" lw 0.5 # grey
set grid back linestyle 81
set border 3 back linestyle 80
set xtics nomirror
set ytics nomirror
set style line 100 lc rgb '#0060ad' lt 1 lw 2 pt 7 ps 1.5
set style line 200 lc rgb '#a2142f' lt 1 lw 2 pt 7 ps 1.5
set pointintervalbox 0
set style line 1 lc rgb '#0072bd' lt 1 lw 1 pt 9 pi -10 ps 2
set style line 2 lc rgb '#77ac30' lt 1 lw 1 pt 7 pi -10 ps 2
set style line 3 lc rgb '#d95319' lt 1 lw 1 pt 1 pi -10 ps 2
set bmargin 4
set lmargin 5
set rmargin 4
unset title
set size 1,1
#set origin 0,0.27
set xlabel "number of cores, -"
set ylabel "Computational time, s"
set key top right
set key spacing 1.5
set key width -12
set yrange [0:1710]
plot "gnuDC.dat" using 1:2 title "DC: GNU Fortran 4.7.2 + Open MPI 1.6.3" w p ls 1, \
"gnuDC.dat" using 1:2:3 with labels center offset 2.,0.7 font "Helvetica,14" tc ls 4 notitle, \
"gnuDC.dat" using 1:3 notitle smooth csplines ls 14
With gnuplot version 5 there is a boxed option which does exactly this: give labels a background and, if you want, also a border. The style is controlled with set style textbox, e.g.
set style textbox opaque noborder
plot ... with labels boxed ...
Applied to your script (with some minor changes due to the changed dash handling since 5.0):
# Line style for axes
set style line 80 lt rgb "#808080"
# Line style for grid
set style line 81 dt 3 # dashed
set style line 81 lt rgb "#808080" lw 0.5 # grey
set grid back linestyle 81
set border 3 back linestyle 80
set tics nomirror
set linetype 1 lc rgb '#0072bd' pt 9 pi -10 ps 2 dt 3
set bmargin 4
set lmargin 5
set rmargin 4
set xlabel "number of cores, -"
set ylabel "Computational time, s"
set key top right
set key spacing 1.5
set key width -12
set yrange [0:1710]
set style textbox opaque noborder
plot "gnuDC.dat" using 1:2 title "DC: GNU Fortran 4.7.2 + Open MPI 1.6.3" w p lt 1, \
"gnuDC.dat" using 1:2:3 with labels boxed center offset 2.,0.7 font "Helvetica,10" tc ls 1 notitle, \
"gnuDC.dat" using 1:3 notitle smooth csplines lt 1
No, for versions 4.6 and earlier there isn't an easy way to achieve this.
I have to plot a multiplot comprising two columns and five rows. I have plotted that but I find the distance in between the plots are big and I want to reduce them. I used the last sample coding (template) as in the website ( http://www.gnuplot.info/demo_canvas/layout.html ). I tried to adjust the top and bottom margin parameters. If I use smaller values the label for x-axis disappears and the distance between plots shortened. So I have to use big values. I just wonder is there any other way to bring the plot nearer to each other? I have given the coding for plot below for your view.
I would be glad to get some insights on this issue.
Thanks in advance
#!/usr/bin/gnuplot
# SET TERMINAL
set terminal postscript color enhanced "Arial" 10 #dashed lw 1 "Helvetica" 14
set output "plot-distribution-isoMalto-thermo.ps"
# SET MACRO
set macro
labelFONT="font 'Arial,20'"
scaleFONT="font 'Arial,14'"
graph="using 1:2"
axislabelFONT="font 'Arial,18' "
#main_titleFONT="font 'times,14'"
graphLabel="at 120,9000 font 'Arial,20' "
position_orienation="at -50,18000 rotate right"
color="linecolor rgb 'black' "
layer1=" w l lt 1 lw 3 lc rgb 'black'"
layer3=" w l lt 3 lw 3 lc rgb 'red' "
layer2=" w l lt 2 lw 3 lc rgb 'green'"
layer4=" w l lt 4 lw 3 lc rgb 'blue'"
# SET MARGINS
set tmargin 0.5
set bmargin 4.0
set lmargin 15
set rmargin 3
# SET RANGE
set xrange [0:180]
set yrange [0:12000]
set xtics nomirror 0, 60, 180 #scaleFONT
set ytics 0, 3000, 12000 #scaleFONT
set format x ""
# MULTIPLOT START
set multiplot layout 5, 2 #title "Multiplot layout 5, 2"
set nokey
# PLOTTING STARTS
#plot1
#set title "Plot 1"
set xtics nomirror
set label 1 "(a)" #graphLabel
plot "angle_output-thermo-malto-L1.dat" #layer1,\
"angle_output-thermo-malto-L3.dat" #layer3
#plot2
#set title "Plot 2"
set label 1 "(b)" #graphLabel
plot "angle_output-thermo-malto-L2.dat" #layer2 ,\
"angle_output-thermo-malto-L4.dat" #layer4
#plot3
#set title "Plot 3"
set label 1 "(c)" #graphLabel
plot "angle_output-thermo-bcmChain1-L1.dat" #layer1 ,\
"angle_output-thermo-bcmChain1-L3.dat" #layer3
#plot4
#set title "Plot 4"
set label 1 "(d)" #graphLabel
plot "angle_output-thermo-bcmChain1-L2.dat" #layer2 ,\
"angle_output-thermo-bcmChain1-L4.dat" #layer4
#plot5
#set title "Plot 5"
set label 1 "(e)" #graphLabel
set label 2 "Distribution / N" #position_orienation #labelFONT
plot "angle_output-thermo-bcmChain2-L1.dat" #layer1 ,\
"angle_output-thermo-bcmChain2-L3.dat" #layer3
#plot6
#set title "Plot 6"
set nolabel
set label 1 "(f)" #graphLabel
plot "angle_output-thermo-bcmChain2-L2.dat" #layer2 ,\
"angle_output-thermo-bcmChain2-L4.dat" #layer4
#plot7
#set title "Plot 7"
set label 1 "(g)" #graphLabel
plot "angle_output-thermo-cello-L1.dat" #layer1 ,\
"angle_output-thermo-cello-L3.dat" #layer3
#plot8
#set title "Plot 8"
set label 1 "(h)" #graphLabel
plot "angle_output-thermo-cello-L2.dat" #layer2 ,\
"angle_output-thermo-cello-L4.dat" #layer4
# for plot 9 and 10
unset yrange
set yrange [0:16000]
set ytics 0, 4000, 16000
set key
#plot9
#set title "Plot 9"
set label 1 "(i)" #graphLabel
set format x
plot "angle_output-thermo-isomalto-L1.dat" #layer1 title "layer1",\
"angle_output-thermo-isomalto-L3.dat" #layer3 title "layer3"
#plot10
#set title "Plot 10"
set label 1 "(j)" #graphLabel
set label "Angle in {/Symbol q} / deg" at -90,-8500 #labelFONT
set format x
plot "angle_output-thermo-isomalto-L2.dat" #layer2 title "layer2",\
"angle_output-thermo-isomalto-L4.dat" #layer4 title "layer4"
# END MULTIPLOT
unset multiplot
#reset
#pause -1
I know this is an old question, but it might be possible to do something with set size to increase the size of each plot (optionally, a set origin for each plot might be necessary). Otherwise, your best bet is to use set lmargin,set rmargin, set bmargin and set tmargin.
You can use set ?margin at ... to set the margin relative to screen coordinates (as opposed to character coordinates in the form you have put it. This will allow you to place the plots exactly where you want to. see http://gnuplot.sourceforge.net/demo/margins.html