i have encountered a strange problem which i cannot overcome.
I'm plotting data from 4 files into 1 and i want every plot to have a different linecolor. However command lt #some number just doesn't work, it gives different linetypes but never colours.
I'm using a script to make a file, to pipe it inside gnuplot to yield a .ps file.
set terminal postscript
set encoding iso_8859_1
set title 'energy difference for a polymer'
set xlabel 'n, polymer length'
set ylabel '{/Symbol D}E, eV'
set key bottom left
set xzeroaxis
set output 'deltaE_PQL.ps'
set boxwidth 0.9 relative
set style fill solid 1.0
plot 'deltaE_plotm2' u 1:2 with lines lt 1 title '| -2 {/Symbol \361}', \
'deltaE_plotm1' u 1:2 with lines lt 2 title '| -1 {/Symbol \361}', \
'deltaE_plot1' u 1:2 with lines lt 3 title '| 1 {/Symbol \361}', \
'deltaE_plot2' u 1:2 with lines lt 4 title '| 2 {/Symbol \361}'
Appreciate any ideas what is wrong here.
In gnuplot console type and check help postscript and use:
set terminal postscript color
Related
I am developing an script which read historical information about the power of the equipment and it prints a curve with that points. I have set the x-axis to display datetime. I did it that way:
# source and filename are both variable names.
set xdata time
set terminal pngcairo enhanced font "arial,10" fontscale 1.0 size 900, 350
set output filename
set key bmargin left horizontal Right noreverse enhanced autotitles box linetype -1 linewidth 1.000
# We set the datetime format
set timefmt '"%Y-%m-%d %H:%M:%S"'
set datafile missing 'None'
set style line 1 lt 2 lc rgb 'blue' lw 1
set style line 2 lt 2 lc rgb 'green' lw 1
set style line 3 lt 2 lc rgb 'red' lw 1
set style line 4 lt 2 lc rgb 'green' lw 1
plot source using 1:2 ls 1 with lines, source using 1:3 ls 2 with lines,source using 1:4 ls 3 with lines
This works fine but the labels in the x-axis which doesn't show the year. Why is this happening? I haven't set properly? I firstly generate a .dat file which contains a line for each point. After I call the GNUPLOT script from python, the file could seems to:
.....................
"2016-08-22 04:00:00" 1812.44580078 2600.0 800
"2016-08-22 04:15:00" 1859.58398438 2600.0 800
"2016-08-22 04:30:00" 1785.85595703 2600.0 800
.....................
This is how the graphs looks like:
How could I achieve it? Thanks in advance.
The timefmt only sets the input time format. To set the label format, use
set format x "%Y-%m-%d %H:%M:%S"
I wrote the following "tmp.dat" datafile
\# 0;1;2;3;4;5;6;7;8;9;10;11;12;13;14;15;16;17;18;19;20
\#inFile;cn;mv;nr;nd;nn;fil;sep;m#enn=;m#enn=;n=;i=;aLea1=;rLea1=;amea1=;rmea1=;NbaLea1=;NbrLea1=;Nbamea1=;Nbrmea1=;rrmen3a1=
ex32new_DMLPG_beta3_der1emeno5/fort.501;0;?;?;?;?;0.0110485435;0.0078125;14;11.1540828402;4225;0;0.00898;0.00158;0.00205;0.00204;0.00898;0.00158;0.00205;0.00204;0.00172
ex32new_DMLPG_beta3_der1emeno5/fort.501;1;0.0165088727;1745;64;0;0.0441941738;0.0078125;42;11.2126074499;1745;1;0.00898;0.00158;0.00205;0.00204;0.00898;0.00158;0.00205;0.00204;0.00172
ex32new_DMLPG_beta3_der1emeno5/fort.501;2;0.0165088858;1726;64;0;0.0441941738;0.0078125;35;11.2027809965;1726;2;0.00898;0.00158;0.00205;0.00204;0.00898;0.00158;0.00205;0.00204;0.00272
ex32new_DMLPG_beta3_der1emeno5/fort.501;3;0.0165088801;1724;64;0;0.0441941738;0.0078125;39;11.214037123;1724;3;0.00898;0.00158;0.00205;0.00204;0.00898;0.00158;0.00205;0.00204;0.00372
ex32new_DMLPG_beta3_der1emeno5/fort.501;4;0.0165088766;1720;64;0;0.0441941738;0.0078125;34;11.1831395349;1720;4;0.00898;0.00158;0.00205;0.00204;0.00898;0.00158;0.00205;0.00204;0.00472
ex32new_DMLPG_beta3_der1emeno5/fort.501;5;0.0165088776;1718;64;0;0.0441941738;0.0078125;32;11.1850989523;1718;5;0.00898;0.00158;0.00205;0.00204;0.00898;0.00158;0.00205;0.00204;0.00572
ex32new_DMLPG_beta3_der1emeno5/fort.501;6;0.0165088822;1710;64;0;0.0441941738;0.0078125;34;11.216374269;1710;6;0.00898;0.00158;0.00205;0.00205;0.00898;0.00158;0.00205;0.00205;0.00672
My gnuplot script
set datafile separator ";"
set datafile missing "?"
set grid
set xlabel "coarsening level"
set ylabel "rrmen3a1"
set xrange [-1:7]
set yrange [*:*]
set terminal pdf color
set output "tmp.pdf"
plot \
"tmp.dat" using 2:21 index 0 with lp title columnheader(1), \
# EOF
does NOT plot the "first" point (0, 0.00172), only points x=1,...,6
Any hint?
The issue is with your plot line
plot "tmp.dat" using 2:21 index 0 with lp title columnheader(1)
This instructs gnuplot to use your first record (which does not include commented lines) to use as column labels. So your first data line is being interpreted as a header. If you do not want to reformat your datafiles, you can plot a dummy curve with the same header file which will act as your data series label. Something like
plot "tmp.dat" using 2:21 index 0 with lp lt 1 lc rgb 'black' notitle, \
"tmp.dat" using ($0):(1/0) index 0 with lp lt 1 lc rgb 'black' columnhead(1)
Note that we have to manually specify the line styles to ensure the keys have the same linestyle as the curves.
I am using gnuplot to postprocess some calculation that I have done and I am having hard time getting gnuplot to select the right lines as it is outputting some strange values that I do not know where come from.
The first 200 points of the results start in line 3 and stop in 202 but that is not working when I use every ::3::202.
Does anyone have any suggestions of what I am doing wrong?
Gnuplot image:
Datafile
set terminal pngcairo transparent nocrop enhanced size 3200,2400 font "arial,40"
set output "Mast41_voltage_muffe.png"
set key right
set samples 500, 500
set xzeroaxis ls 1 lt 8 lw 3
set style line 12 lc rgb '#808080' lt 0 lw 1
set style line 13 lt 0 lw 3
set grid back ls 12
set decimalsign '.'
set datafile separator whitespace
set ylabel "Spenna [pu]"
set xlabel "Timi [s]"
plot "mrunout_01.out" every ::3::202 using 2:3 title '5 ohm' with lines lw 3 linecolor rgb '#D0006E',\
"mrunout_01.out" every ::203::402 using 2:3 title '10 ohm' with lines lw 3 linecolor rgb '#015DD4',\
"mrunout_01.out" every ::403::602 using 2:3 title '15 ohm' with lines lw 3 linecolor rgb '#F80419',\
"mrunout_01.out" every ::603::802 using 2:3 title '20 ohm' with lines lw 3 linecolor rgb '#07826A'
unset output
unset zeroaxis
unset terminal
every refers to the actual plottable points. In your case, you have to skip 2 lines and the bunch of data at the end of your datafile.
Since you know the actual lines you need to plot I would pre-parse the file with some external tools like sed
So you can omit the every and your plot line becomes:
plot "< sed -n '3,202p' mrunout_01.out" using 2:3 title '5 ohm' with lp lw 3 linecolor rgb '#D0006E'
With yor datafile as it is, gnuplot has problems reading it. It can't even run stats on it:
stats 'mrunout_01.out'
bad data on line 1 of file mrunout_01.out
There is no need for using external tools, you can simply do it with gnuplot.
It's advantageous with your data that it is regular, every 200 points plotted in a different color.
And the data you want to plot is separated by one empty line from some additional data at the end of the file which you don't want to plot.
So, you simply address the 4th set of 200 lines in the 0th block via every ::600:0:799:0.
From help every:
Syntax:
plot 'file' every {<point_incr>}
{:{<block_incr>}
{:{<start_point>}
{:{<start_block>}
{:{<end_point>}
{:<end_block>}}}}}
Comments:
you can skip two lines at the beginning of the files with skip 2
you can plot your curves in a loop plot for [i=1:4] ...
you can define your color myColor(n) via index n from a string "#D0006E #015DD4 #F80419 #07826A"
you can define the legend myTitle(n) also from a list "5 10 15 20"
Script: (tested with gnuplot 5.0.0, version at the time of OP's question)
### plot parts of a file in a loop
reset session
FILE = "SO36103041.dat"
myColor(n) = word("#D0006E #015DD4 #F80419 #07826A",n)
myTitle(n) = word("5 10 15 20",n)
set xlabel "Timi [s]"
set ylabel "Spenna [pu]"
set yrange[0:30]
plot for [i=1:4] FILE u 2:3 skip 2 every ::((i-1)*200):0:(200*i-1):0 \
w l lw 3 lc rgb myColor(i) ti myTitle(i)
### end of script
Result:
I am executing the following gnuplot script:
set title "Efficiency scatter plot"
set xlabel "perf_1"
set ylabel "secondary report"
set log x
set log y
set xrange [0.1:40.0]
set yrange [0.1:40.0]
set terminal png medium
set output "./graph1.png"
set size square
set multiplot
set pointsize 0.3
set style line 6 pt 6
set datafile separator ","
set border 3
set xtics nomirror
set ytics nomirror
plot '/tmp/data.csv' using 3:1 with points pt 1 lt 3 lc var title "perf_20140113131309", \
'/tmp/data.csv' using 3:2 with points pt 1 lt 1 lc var title "perf_1"
plot x notitle
plot 2*x notitle
plot 0.5*x notitle
obtaining the following error message
"script.gnuplot", line 20: Not enough columns for variable color
Could you please guide me in order to find what I am doing wrong.
By the way the gnuplot version is '4.6 patchlevel 3' the data.csv files used is
0.1,0.1,40.0
0.14,0.14,40.0
0.32,0.32,40.0
0.7,0.74,40.0
Thanks in advance!
That means, that you need to specify one more column in your using statement: The first one is the x-coordinate, the second one the y-coordinate. The one for the variable line color is missing.
Use e.g.
plot '/tmp/data.csv' using 3:1:0 with points pt 1 lt 3 lc var
to use the row number (zeroth column) as linetype index. You can also use e.g. linecolor palette so select the color from the currently defined color palette.
I have two different files to plot in the gnuplot. they use a) different separator b) different time on x-axis
hence for each of them to plot separately I need to pass
set datafile separator
set timefmt
I would like to impose/overlay both data in a single graph such, that they are aligned with time
how could I do this?
The problem with the different separators can be addressed by using the format after the using modifier to specify a different separator for each file, e.g.:
plot 'file1.dat' u 1:2 '%lf,%lf'
plots a two column file with comma separator. See help\using for some more detail.
I am not expert of time formats, so I don't know how to deal with the timestamp format problem. But maybe you can use some function like strftime(). I never tried it, but it seems to me it does what you need.
You're right, you will need to pass set datafile separator and set timefmt once per file. You can do it like this:
set terminal <whatever>
set output <whatever.wht>
set xdata time # tell gnuplot to parse x data as time
set format x '%F' # time format to display on plot x axis
set datafile separator ' ' # separator 1
set timefmt '%F' # time format 1
plot 'file1'
set datafile separator ',' # separator 2
set timefmt '%s' # time format 2
replot 'file2'
The replot command by itself replots the previous line, and if you specify another line to be plotted that will go on top of the first one like I did here.
It seems to me that you have 2 options. The first is to pick a datafile format and beat both datafiles into that format, maybe using awk:
plot '<awk "-f;" "{print $1,$2}" data1' using 1:2 w lines,\
'data2' using 1:2 w lines
*Note, your awk command will almost certainly be different, this just shows how to use awk in an inline pipe.
Your second option is to use multiplot with explicit axes alignment:
set multiplot
set xdata time
set datafile sep ';' #separator for first file
set timefmt "..." #time format for first file
set lmargin at screen 0.9
set rmargin at screen 0.1
set tmargin at screen 0.9
set bmargin at screen 0.1
unset key
plot 'data1' u 1:2 w lines ls 1 nontitle
set key #The second plot command needs to add both "titles" to the legend/key.
set datafile sep ',' #separator for second file
set timefmt "..." #time format for second file
unset border
unset xtics
unset ytics
#unset other stuff that you set to prevent it from being plotted twice.
plot NaN w lines ls 1 title "title-for-plot-1", \
'data1' u 1:2 w lines ls 2 title "title-for-plot-2"
The plot NaN trick is only necessary if you want to have things show up correctly in the legend. If you're not using a legend, you can not worry about it.
This works for me :
reset
set term pngcairo
set output 'wall.png'
set xlabel "Length (meter)"
set ylabel "error (meter)"
set style line 1 lt 1 linecolor rgb "yellow" lw 10 pt 1
set style line 2 lt 1 linecolor rgb "green" lw 10 pt 1
set style line 3 lt 1 linecolor rgb "blue" lw 10 pt 1
set datafile separator ","
set key
set auto x
set xtics 1, 2, 9
set yrange [2:7]
set grid
set label "(Disabled)" at -.8, 1.8
plot "file1.csv" using 1:2 ls 1 title "one" with lines ,\
"file2.csv" using 1:2 ls 2 title "two" with lines ,\
"file3.csv" using 1:2 ls 3 title "three" with lines
set output