How to change thickness of a single in line in EXISTING plot - plot

I create a plot with many (50+) lines on it.
I would like to set up a keybind such that I can toggle through each line and change it's thickness, and so making that line stand-out from the rest, then when I press the key again, the next line becomes thicker.
That way I can examine each line clearly, next to the others.
I know how to assign keys, but I don't know how to change the thickness of an exiting line on an existing plot.
How can I go about this?
Moon
EDIT 1
Is it possible to do something like this:
set style line 1 lt 2 lc rgb "red" lw 3
set style line 2 lt 2 lc rgb "orange" lw 2
set style line 3 lt 2 lc rgb "yellow" lw 3
set style line 4 lt 2 lc rgb "green" lw
savedls1 = ls 1
savedls2 = ls 2
savedls3 = ls 3
savedls4 = ls 4
plot <whatever> ls 2 #Original style
set style line 2 lt 2 lc rgb "black" lw 2 #new temp style
plot <whatever> ls 2; replot #Temp new style
set style line 2 savedls2
plot <whatever> ls 2; replot #Back to original style

In the command line (v4.6 patchlevel 3), you can do it like this:
Specify a line style:
set style line 1 lt 2 lw 2 pt 3 ps 0.5
When plotting, specify this line style:
plot sin(x) ls 1
Now, you can change this line style, e.g. changing the line width:
set style line 1 lt 2 lw 4 pt 3 ps 0.5
A simple replot will produce the same graph with the updated line style.
EDIT
Christoph provided this information in a comment, addressing the question of a key-bind:
It is enough in step 3 to change the linewidth, the rest remains unchanged:
set style line 1 lw 4
That would allow you to define two different linewidths and toggle between them:
lw_small = 2
lw_thick = 5
set style line 1 lt 2 lw lw_small pt 3 ps 0.5
plot sin(x) ls 1
set style line 1 lw lw_thick # here, everything but the line-width stays constant
pause 3
replot
set style line 1 lw lw_small
pause 3
replot

Related

Add a coloured line to a label in gnuplot?

I was wondering if it is possible to add a coloured line to a label command in gnuplot? That is, say I would like to add a red line after some text in a label command:
set label "some text here which is then followed by a red horizontal line -----" at 100,200 front
Basically, I want to mimic the usual presentation of the key in gnuplot in a label command. I already have one key and another key is not allowed within the same plot environment, so I want to manually construct a second key through the label command.
Thanks in advance.
I would do it the following way. Check the details of help arrow and help label.
Edit: using separate lines and labels is certainly more code but you have full flexibility. I guess it depends on what exactly you want to do.
Code:
### labels with lines
reset session
set size ratio -1
set arrow 1 from 4,0 to 7,0 lc "red" lw 2 nohead
set label 1 at 4,0 "Some text" right offset -1,0
set arrow 2 from 2,-2 to 5,-2 lc "red" lw 2 dt 3 nohead
set label 2 at 5,-2 "Some text" left offset 1,0
set arrow 3 from -6,5 to -2,5 lc "red" lw 2 dt 1 nohead
set label 3 at -4,5 "Some text" center offset 0,-1
set arrow 4 from -6,-2 length 5.5 angle 45 lc "red" lw 2 dt 3 nohead
set label 4 at -6,-2 "Some text" font ",14" right rotate by 45 offset -1,0
plot x w l lc "blue"
### end of code
Result:
You can have a second key by plotting data that is all invalid (NaN, not a number). For example,
cat >data <<\!
17 15
18 5
19 10
21 7
!
gnuplot -persist <<\!
plot "data" u 1:2 with lines title "plot1", \
"" u (NaN):(NaN) with lines title "plot2"
!
You can use a plot clause with the keyword keyentry rather than a file name to generate an extra title and line/point/fill sample for the key. You can also use the keyword at <x-pos>,<y-pos> to place this extra title somewhere else on the page.
Examples from the on-line demo set:
custom key generation
extra key entries
Quick example here:
set xrange [0:20]
plot x**2, x**3, \
keyentry with lines dt '-' lc "red" title "Extra title" at graph 0.25, graph 0.75

Draw front arrow over image

I have the following image using the code
set terminal png
set output 'plot.png'
set xlabel "GC (%)"
set ylabel "Proportion of genome"
set sample 1000
set xrange[0:100]
set yrange[0:]
set boxwidth 1
set style fill solid
set key off
set style line 1 lt 1 lc rgb "#0000FF" lw 3
set style line 2 lt 2 lc rgb "#32CD32" lw 3
Cauchy(x,xo,wi) = (1./pi) * wi / ((x - xo)**2 + wi**2)
plot 'compositionGC.txt' w boxes, 0.368187*Cauchy(x, 41.4226,1.72758) + 0.631813*Cauchy(x, 51.8272, 0.464711) ls 2
set yrange[0:GPVAL_Y_MAX]
set arrow from 47.2,0 to 47.2,GPVAL_Y_MAX front ls 1
replot
I have everything I need except that I want a vertical blue arrow separating the two peaks at 47.2 in the x-axis in the front. I cannot get it to work.
Do not change the yrange and replot.
Use this arrow command before the initial plot:
set arrow 1 from 47.2, graph 0 to 47.2, graph 1 front lc "blue"

Line plot in GnuPlot where line width is a third column in my data file?

I have a datafile that has three columns :
1 1.0 1
2 1.5 2
3 0.0 3
4 1.2 2.5
5 1.0 1
6 1.1 5
where the first column is my X value, the second column is my Y value, and the third column is the line width. I'd like for each line segment to be plotted according to the third column line width.
I tried:
plot 'file1.dat' using 1:2:3 with lines lw var
But I get undefined variable: var error.
Is this possible in gnuplot?
Thanks.
If you define column 3 as the linewidth between points n and n+1 (so the value of col. 3 of the row will be ignored) you can cheat:
stat 'file1.dat'
n=STATS_records
plot for [i=0:0] 'file1.dat' using 1:2:(alma=$3) every ::i::i w l lc 1 lw 1
plot for [i=0:n-1] 'file1.dat' using 1:2:(alma=$3) every ::i::i+1 w l lc 1 lw alma notitle
OR
plot 'file1.dat' u 0:1
n=GPVAL_DATA_X_MAX
plot for [i=0:0] 'file1.dat' using 1:2:(alma=$3) every ::i::i w l lc 1 lw 1
plot for [i=0:n] 'file1.dat' using 1:2:(alma=$3) every ::i::i+1 w l lc 1 lw alma notitle
You need the first plot for[i=0:0] to 'initialize' variable 'alma'.
stat 'varwidth.dat' nooutput
n=STATS_records; prex=0; prey=0; SC=2 # How y-axis is expanded relative to the x-axis
plot for [i=0:n-1] for [try=0:1] '' using 1:((try==0?dx=$1-prex:1),(try==0?sl=($2-prey)/(dx==0?1:dx):1),(try==0?prex=$1:1),(try==0?prey=$2:1),$2+(w=$3/80*sqrt(1+(SC*sl)**2))/2):($2-w/2) every ::i::i+1 w filledcurves lc 1 notitle
This produces the correct line width (as opposed to the “line height”, as in the answer to a related question). I have no clue how to make the “lines” match where they join (seems to be impossible without support from inside gnuplot).
(This assumes that the data in the question is in a file varwidth.dat.)
As mentioned by #Christoph in the comments, you have N points (rows) and N linewidth values, but only N-1 connecting lines.
So, you have to decide which linewidth value should be applied to which line. Which one to skip? The first one or the last one? Here, the last one is skipped.
It's basically, a shortened version of #Tom Solid's solution. Actually, you can get the initial value already during the stats command.
As #Joce mentioned and #Ilya Zakharevich is suggesting in his answer, if you do not fear some extra effort you can also draw tapered lines.
Data:
# x y linewidth
1 1.0 1
2 1.5 2
3 0.0 3
4 1.2 2.5
5 1.0 1
6 1.1 5
Script: (works with gnuplot 4.6.0, March 2012)
### workaround for variable linewidth
reset
FILE = "SO/SO37925489.dat"
stats FILE u ((N=$0)==0?Lw0=$3:0) nooutput
set grid
plot for [i=0:N] FILE u 1:2:(Lw0=$3) every ::i::i+1 w l lw Lw0 lc rgb "red" notitle
### end of script
Result:

How to plot a specific graph in gnuplot

I have a file that I need to plot in a graph that looks similar to this:
gnuplot sample graph
Here is my file that I am trying to plot:
441.81 823.36 192765 3044.68 4242.61
X 2609.3 4901.96 8306.6 12058.18
1632.27 4098.15 9299.14 16295.19 24665.59
I can do a simple plot, but changing the line types and using a file is what I am having trouble with. I'm not sure how to get the data from the file into the plot and make it formatted like the sample image.
You probably should dig a little deeper into gnuplot. A good start is this article on plotting data.
Anyway, let's define three distinct line styles:
set style line 1 lc 'blue' lt 1 lw 2 pt 6 ps 1.5
set style line 2 lc 'red' lt 1 lw 2 pt 6 ps 1.5
set style line 3 lc 'green' lt 1 lw 2 pt 6 ps 1.5
Then, we can call the plot function on our inputFile:
plot 'inptFile' u 1:2 w lp ls 1, '' u 1:3 w lp ls 2, '' u 1:4 w lp ls 3
(u 1:2 stands for using 1:2 and means that we use the value in the first column as x-coordinate and the value in the second column as the y-coordinate. )
Note that our inputFile looks like this (i.e., each line contains a point's x and y-coordinate):
-1 2 3 4
0 1 2 4
1 2 4 16
2 3 16 8
Output:

gnuplot highlighting points when with lines

I have 4 points I would like to plot using gnuplot, but with lines. The problem is, I can't find how to highlight these 4 points on the drawn line. I would like for the plot to be a line through the points, but that these points are also clearly marked. An example generated by excel. What I know is either drawing only points, or only a line with no highlighted points. Is a combination possible in gnuplot?
From gnuplot docs, define styles as:
set style line 1 lc rgb '#0060ad' lt 1 lw 2 pt 5 ps 1.5 # blue
set style line 2 lc rgb '#dd181f' lt 1 lw 2 pt 7 ps 1.5 # red
...
and plot:
plot ... w lp ls 1 # Use line style 1
where:
lc - linecolor
lt - linetype
lw - linewidth
pt - pointtype
ps - pointsize
w - with
lp - linespoints
ls - linestyle
or one line shorthand:
plot ... w lp lc rgb 'cyan' lw 2 pt 5
line style 1 will produce blue line with square points

Resources