setting the linewidth in gnuplot when the color is given by a 4th axis - gnuplot

To plot 3D data xyz with the color given by a 4th variable I can use the command
splot 'au' u 1:2:3:4 linecolor palette with lines
where au is a file containing 4 columns of data.
If I try to adjust the width of the line to make it easier to see it gives the error below. What it the correct way to set the line width when taking colour from a palate given by a 4th axis
gnuplot> splot 'au' u 1:2:3:6 linecolor palette with lines lw 2
^
duplicated or contradicting arguments in plot options

Line properties must all come next to each other in the plot command; you can't stick something else (in this case with lines) in the middle. Use either
splot 'au' u 1:2:3:6 linecolor palette lw 2 with lines
or
splot 'au' u 1:2:3:6 with lines linecolor palette lw 2

Related

Gnuplot: Alternating colors in fenceplots

I want to to plot a fenceplot with alternating fence colors. In this case I want black and grey. I used the following code:
splot for [i=0:300:25] "fenceplot.csv" index i u 1:2:3 w lines
The number of fences defined in my data file is dynamic and is usually between 250-350 fences.
Because the variable i changes by 25 between subsequent curves you can decide which color to use for a given line by testing whether i is even or odd:
set style line 1 linecolor "black"
set style line 2 linecolor "grey"
splot for [i=0:300:25] "fenceplot.csv" index i u 1:2:3 w lines linestyle 1+i%2
Slightly more robust would be
splot for [i=0:12] "fenceplot.csv" index i*25 u 1:2:3 w lines linestyle 1+i%2
because then you can also replace 25 by an even number.

Gnuplot plotting wrong lines and some strange values as well

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:

How to make this gnuplot diagram

This is my gnuplot digram. My digram is this:
I want to create this one:
From each point on the line. create a line to X and Y:
Change the color of the points to another thing than red.
This is my plot script:
set terminal png size 900,600 enhanced font "Helvetica,20"
set output 'All recived Packet in the network per second.png'
set grid
set xlabel "Transmision Range"
set ylabel "All of recived Packet in the network per second"
set title "Recive Packet pre second"
plot "NumOfRcvPkt.dat" using 2:3 title 'Transmision Range' with linespoints
Also here is the content of NumOfRcvPkt.dat file:
0 15 124
1 20 105
2 25 82
This is achieved as follows:
xmin=14 ; ymin=80
set xrange [xmin:*] ; set yrange [ymin:*]
plot "data" u 2:3 w l lc rgb "red", \
"" u 2:3 w p pt 7 lc rgb "blue", \
"" u (xmin):3:($2-xmin):(0) w vectors nohead lt 2 lc rgb "black", \
"" u 2:(ymin):(0):($3-ymin) w vectors nohead lt 2 lc rgb "black"
The first two lines set the ranges. This is important because you need to know where the edges lie in order to draw your black dashed lines.
Then, for the plot command, the first line plots the data with red lines, the second plots the data with blue circles, the third one plots horizontal black dashed lines and the fourth one plot vertical dashed lines. In order for your terminal to accept dashed styles (selected with lt 2) you need to add dashed, e.g. set term png dashed.
This is the result:

Gnuplot: dashed to solid lines

I'm having troubles with gnuplot rendering all but one line as dashed. Namely, after setting
gnuplot> set terminal postscript eps color
gnuplot> set term postscript eps color linewidth 2
gnuplot> set output "local1.eps"
gnuplot> set pointsize 0.5
and invoking
plot "YY_globalized.txt" using 1:2 title "Global approach" with linespoints linetype 1 pointtype 1, "YY_localizedPlain.txt" using 1:2 title "Localized Opt" with linespoints linetype 11 pointtype 2
one line is solid, while the other is dashed. In case of multiple lines, each is getting its own style, different from dashed. Is there a way to specify that all the lines should be solid, but with different color (and, possibly, with different point style)?
Thanks.
Just specify the the terminal option 'solid' in your first line:
gnuplot> set terminal postscript eps color solid
Yes, there is a way. You specify linetype for each dataset to 1 to force a solid line and change the line color with another option to distinguish them. Here is your modified plot command:
plot "YY_globalized.txt" using 1:2 title "Global approach" with linespoints linetype 1 pointtype 1 linecolor 1, "YY_localizedPlain.txt" using 1:2 title "Localized Opt" with linespoints linetype 1 pointtype 2 linecolor 2
This produces first line solid red, the second line solid green.
In essence (omitting irrelevant options for readability) it comes down to this
plot "data1" linetype 1 linecolor 1 \
, "data2" linetype 1 linecolor 2
There might be a smarter way to unify some line options using line styles (see documentation), but you would have to specify line color for each of the data sets by hand anyway.

setting multiple labels at the top of the x-axis

After the answer got in my earlier post drawing vertical lines in between bezier curves, I have been trying to label the segments separated by the dotted lines. I used x2label but found out that if I use it multiple times then the data gets replaced though they are positioned in different places. Below is the script:
set term x11 persist
set title "Animation curves"
set xlabel "Time (secs.)"
set ylabel "Parameter"
set x2label "Phoneme1" offset -35
set pointsize 2
set key off
set style line 2 lt 0 lc 1 lw 2
plot [0.04:0.15] "curve.dat" u 1:2 smooth csplines ls 1, "" u 1:($2-0.2):(0):(0.3) w vectors nohead ls 2, \
"curve.dat" u 1:2 with points
The output is the following.
I want to label Phoneme1, Phoneme2...and so on.. on top of each segment. How would I do it? Also as I was suggested in my earlier post to play with the line "" u 1:($2-0.2):(0):(0.3) w vectors nohead ls 2 to get a top to bottom vertical lines. But that also did not work. How do I get the lines from top margin to bottom? Thank you.
The horizontal lines
The horizontal lines can be accomplished with setting the yrange to an explicit value. Otherwise gnuplot would try to get some space between the lines and the axis. You could choose the values
set yrange [0.3:1.2]
Then you simply modify the vector using directions like so:
"" u 1:(0.3):(0):(1.2) w vectors nohead ls 2
(see below for the complete script)
The labeling of the sections
A quick way of doing this with your set of data would be this:
set key off
set style line 2 lt 0 lc 1 lw 2
set yrange [0.3:1.2]
plot [0.04:0.15] "Data.csv" u 1:2 smooth csplines ls 1, \
"" u 1:(0.3):(0):(1.2) w vectors nohead ls 2, \
"" u ($1+0.005):(1):(sprintf("P %d", $0)) w labels
However, this will probably not look the way you want it to look. You could think of modifying your data file to also include some information about the labeling like:
#x-value y-value x-label y-label label
0.06 0.694821399177 0.65 0.1 Phoneme1
0.07 0.543022222222 0.75 0.1 Phoneme2
Then the labels line would simply look like:
"" u 3:4:5 w labels
The complete plot then looks like this:

Resources