Gnuplot types of error bars - plot

Can we change the type of line used by gnuplot in the errorbars?
This is my gnuplot code:
set terminal postscript eps color
set output '| epstopdf --filter --outfile=plot.pdf'
set xlabel "Simulation days"
set xtics nomirror
set ylabel "Time (seconds)"
set ytics nomirror
set logscale y
set key left top
plot "data1.csv" using 1:($2/1000):($3/1000) with yerrorbars pt 5,\
"data2.csv" using 1:($2/1000):($3/1000) with yerrorbars pt 7
The error bars from the first plot are different from the second one.
The first line is solid, but the second is dotted.
Its possible to define the style of the error bar?

In your case, the easiest option is to use the solid terminal option to have only solid lines:
set terminal postscript eps color solid lw 3
set output '| epstopdf --filter --outfile=plot.pdf'
set samples 10
set xrange [0:10]
unset key
plot '+' using 1:1:(0.2*$1) w yerrorbars, \
'' using 1:(1.5*$1):(0.1*$1) w yerrorbars
Result with 4.6.4:
Alternatively, you can use lt 1 lc 2 for the second plot, which selects the line pattern of the first linetype (which is solid), and the color of the second one:
plot '+' using 1:1:(0.2*$1) w yerrorbars, \
'' using 1:(1.5*$1):(0.1*$1) lt 1 lc 2 w yerrorbars

Related

How to fix xtics label overlapping in gnuplot

I'm using GNUPlot to draw the graph of five real-valued functions. I think it is easy to solve, but I am a beginner.
My x-axis has problems with its label. All the xtics numbers are overlapping, and I have no idea why.
My .plt plots 3 files: an .eps, an pb .eps and a .png. It receives a .100 file, which is 6 columns of numbers. The first column represents values for t and the other five columns represent values for each function at respective t.
My .plt file is:
reset
set terminal windows
set style line 1 lt 1 linewidth 3
set style line 2 lt 2 linewidth 3
set style line 3 lt 3 linewidth 3
set style line 4 lt 4 linewidth 3
set style line 5 lt 5 linewidth 3
set style line 6 lt 6 linewidth 3
set border linewidth 3
set xzeroaxis
set yzeroaxis
set xlabel '{/Helvetica-Oblique t (dias)}' enhanced font ',28'
set key center top
set key center right
set key top right
set key box
set tics scale 1.5
set grid ytics
set grid xtics
set xtics 0,250,3500
set ytics 0,0.1,1
set title 'Simulacao' font ',26'
set samples 100
plot "./fort.100" using 1:2 with lines title 'Ms' linestyle 1, \
"./fort.100" using 1:3 with lines title 'Mi' linestyle 2, \
"./fort.100" using 1:4 with lines title 'A ' linestyle 3, \
"./fort.100" using 1:5 with lines title 'H ' linestyle 4, \
"./fort.100" using 1:6 with lines title 'I ' linestyle 5
pause -1
set terminal postscript eps enhanced
set termoption enhanced
set output "xsol-pb.eps"
replot
set terminal postscript eps enhanced color font ',22'
set termoption enhanced
set output "xsol.eps"
replot
set terminal png giant size 900,600 enhanced
set termoption enhanced
set output "xsol.png"
replot
Link for my .eps graph:
How can I fix this problem?
I am also having a problem with the table, at the right top corner of the image. How to fix that?
Two possibilities to avoid "collisions" of data and key:
adjust your scale such that the curve is below the key, in your case e.g. set yrange[0:1.5]
shift the positon of your key, e.g. set key center right or set key at graph 0.8, graph 0.8. Check help key for more information.

Add an aditional space to xrange and yrange

I want to plot multiple files using a Gnuplot script.
However, I'm having some trouble to make it perfect.
My actual plots are something like that:
However, the linepoints plot is touching both the x-axis and the y-axis.
Therefore, I want to add extra space on xrange and yrange and get
which does not touch my axis.
I could to it manually using set xrange and set yrange.
However, I need to plot more than 100 different files, and it will be very time-consuming to do so.
There is some manner to automatically increase the size of xrange and yrange by some units?
My Gnuplot code is below.
#!/usr/bin/env gnuplot
set terminal epslatex size 7.5,3 standalone
set output 'pareto.tex'
set style fill solid 0.8
set ytics nomirror
set xtics nomirror
set grid lc rgb "#F2F2F2"
set xlabel 'Z_1'
set ylabel 'Z_2'
set xrange [170:215]
set yrange [7:40]
set style line 1 lt rgb "#000000" lw 12 pt 7 pointsize 3
plot "../exact.dat" using 1:2 title '$aug\,\epsilon$-CM' with linespoints ls 1
unset output
set output # finish the current output file
system('pdflatex --interaction=batchmode pareto.tex')
unset terminal
system
The command you are looking for is set offset. See the documentation for a full description.
Example:
set multiplot layout 3,1
# Default placement
plot 'silver.dat' with lines
# Additional whitespace combined with auto-extenstion to nearest ticmark
set offset 20,20,20,20
replot
# Additional whitespace with no auto-extension to nearest ticmark
set xrange [*:*] noextend; set yrange [*:*] noextend
replot
unset multiplot

How choose which column put on axis like label?

I have a csv file like this:
10557,1925080,1236052,1210752,1182492
11254,3159084,2264460,2187584,2144416
11334,2348036,1540692,1504536,1458332
11456,1607704,993228,974676,960308
.....
I want create a chart with these data. I want use the first column as x-axes label, and put all other column like different line inside the chart. how can I do it?
This is my code
set terminal pngcairo enhanced font "arial,10" fontscale 2.0 size 1680, 1024
set size 1,1
set ylabel '[y]'
set xlabel '[FIRST COLUMN FROM CSV]'
set datafile separator ","
set autoscale fix
set key top left
set key box
set output 'Figure1.png'
plot \
"figure1.csv" using 2 w l linewidth 3 lc rgb "black" title "second colum", \
"figure1.csv" using 3 w l linewidth 3 lc rgb "black" title "third colum", \
"figure1.csv" using 4 w l linewidth 3 dashtype 2 title "fourth colum", \
"figure1.csv" using 5 w l linewidth 3 dashtype 5 title "fifth colum"
To get evenly spaced tics on the x-axis which get labelled with the values from the first column use xticlabels:
plot "figure.csv" using 0:2:xticlabels(1)

generating one legend in multiplot and and placing it at the last column and last row

I am trying to arrange several plots with histograms in a multiplot mode.
I have successfully plotted them. (Please see the attached pic)
.
But I have a problem with plotting the legend (or key).
I want the legend to be at the middle of the last row and the most right column in the multiplot (please see the attached plot).
I have tried to plot the legend but no avail. To have a better understanding of what I did, I have provided the whole script on which I am working.
Hope I get some help to draw the legend and place that at last column and last row.
#!/usr/bin/gnuplot
#########################################################################################
set terminal postscript eps size 7.8,6.8 enhanced color font 'Helvetica,20'
set output 'yy_HB_all_Chap6_LYOsystems.eps'
#########################################################################################
set macro
labelFONT="font 'Helvetica,24'"
labelFONTin="font 'Helvetica,18'"
scaleFONT="font 'Helvetica,16'"
scaleFONTx="font 'Helvetica,15'"
keyFONT="font 'Helvetica,24'"
set key spacing 3.5 samplen 3 #keyFONT
#########################################################################################
set xtics #scaleFONT
set ytics #scaleFONT
set xlabel "Oxygen" #labelFONT
set ylabel "Hydrogen Bond" #labelFONT offset 2.2,0
#set label "Hydrogen Bonds" at -2.0,0.35 rotate by 90 right #labelFONT
#########################################################################################33
set style histogram rowstacked
set style data histograms
set boxwidth 0.75 absolute
set style fill solid 1.00 noborder
#set boxwidth 0.8
#set style fill transparent solid 0.75 noborder
set yrange [0:2.5]
set xrange [0:12]
set multiplot layout 3,2 title ""
##PLOT_1 (1,1)
set label "(a) {/Symbol-Oblique b}Mal-C_{12}(12%wat)" at 1, 2.2 #labelFONTin
plot "HB-data-maltoLyo12per.dat" using 2 t "Lipid-lipid" lc rgb "#191970", '' using 3:xticlabels(5) t "Water-lipid" lc rgb "#6495ED"
###PLOT_2 (1,2)
unset label
set label "(b) {/Symbol-Oblique b}Mal-C_{12}(23%wat)" at 1, 2.2 #labelFONTin
plot "HB-data-maltoLyo23per.dat" using 2 t "Lipid-lipid" lc rgb "#191970", '' using 3:xticlabels(5) t "Water-lipid" lc rgb "#6495ED"
###PLOT_3 (2,1)
unset label
set label "(c) {/Symbol-Oblique b}Mal-C_{12}C_{8}({/Helvetica-Italic R}) " at 1, 2.2 #labelFONTin
plot "HB-data-bcmLyo25perR.dat" using 2 t "Lipid-lipid" lc rgb "#191970", '' using 3:xticlabels(5) t "Water-lipid" lc rgb "#6495ED"
###PLOT_4 (2,2)
unset label
set label "(d) {/Symbol-Oblique b}Mal-C_{12}C_{8}({/Helvetica-Italic S}) " at 1, 2.2 #labelFONTin
plot "HB-data-bcmLyo25perS.dat" using 2 t "Lipid-lipid" lc rgb "#191970", '' using 3:xticlabels(5) t "Water-lipid" lc rgb "#6495ED"
###PLOT_4 (3,1)
unset label
set label "(e) {/Symbol-Oblique b}Mal-C_{12}C_{8}({/Helvetica-Italic RS}) " at 1, 2.2 #labelFONTin
plot "HB-data-bcmLyo25perRS.dat" using 2 t "Lipid-lipid" lc rgb "#191970", '' using 3:xticlabels(5) t "Water-lipid" lc rgb "#6495ED"
######################################################################################################
#set size 0.3,0.3
#set origin 0.70,0.6
set bmargin at screen 0
set key center #keyFONT
set border 0
unset xlabel
unset ylabel
unset label
unset tics
set format x ""
set format y ""
set yrange [0:1]
plot 2 ls 1 title "Lipid-lipid",\
2 ls 2 title "Water-lipid"
######################################################################################################
unset multiplot
You can do this with a trick:
unset key
just after the set multiplot command, so no key is displayed for the first plots. Then, before the last one, issue a command that will restore the key and put it in the right place, that is, outside of the current plot:
###PLOT_4 (3,1)
set key at graph 1.5,screen 0.5 center center

GNUPLOT: saving data from smooth cumulative

I make this simple cumulative and histogram plot of a uniform random distribution of real numbers (n=1000):
http://www.filedropper.com/random1_1: random1.dat
And the macro is:
unset key
clear
reset
n=120 #number of intervals
max=4. #max value
min=1. #min value
width=(max-min)/n #interval width
#function used to map a value to the intervals
bin(x,width)=width*floor(x/width)+width/2.0 # cosi viene centrato in mezzo
set xtics min,(max-min)/10,max
set boxwidth width
set style fill solid 0.5 border
set ylabel 'Frequency'
set y2label 'Cumulative frequency'
set y2tics 0,100,1000
set ytics nomirror
set xrange [0.9:4.1]
set yrange [0:25]
set terminal pngcairo size 800,500 enhanced font 'Verdana,14'
set output "testCum.png"
plot 'random1.dat' using (bin($1,width)):(1.0) smooth frequency with boxes title 'histogram',\
'' using (bin($1,width)):(1.0) smooth cumulative axis x1y2 w l lt 2 lw 2 lc rgb 'green' title 'cumul'
Now the output.png is:
How I can tell to Gnuplot I want to take not only the cumulative plot but also the numbers coming from it saved in a particular file.dat ?
You can save the data after applying smooth with set table .... In the simplest case, if you need only the cumulative data, just use:
set table 'random1-smoothed.dat'
plot 'random1.dat' using (bin($1,width)):(1.0) smooth cumulative
unset table
For better inclusion in your script you could also wrap the whole, existing plot command in set table:
...
set table 'random1-smoothed.dat'
plot 'random1.dat' using (bin($1,width)):(1.0) smooth frequency with boxes title 'histogram',\
'' using (bin($1,width)):(1.0) smooth cumulative axis x1y2 w l lt 2 lw 2 lc rgb 'green' title 'cumul'
unset table
set terminal pngcairo size 800,500 enhanced font 'Verdana,14'
set output "testCum.png"
replot

Resources