gnuplot highlighting points when with lines - plot

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

Related

Set two y axes is gnuplot

I have 2 files with points
C:\1.txt
C:\2.txt
I'm trying to plot both of them into the same plot.
set style line 1 lc rgb '#0060ad' lt 2 lw 2 pt 0 ps 1.5
plot 'C:\1.txt' with linespoints ls 1 , 'C:\2.txt' with linespoints ls 1
How to set 2 different y-axis range for them ([0:6000] and [0:150] for example)?
link to documentation
i've got it.
set yrange [0:6000]
set y2range [0:150]
set xrange [0:5]
set x2range [0:5]
set y2tics
plot 'C:\1.txt' axes x1y1 with lines , 'C:\2.txt' axes x2y2 with line

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:

How to change thickness of a single in line in EXISTING 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

Plot points linked with edges using gnuplot

I have a file of points (x, y) that I plot using gnuplot. If I have another file that shows which point is linked with which other point by an edge (e.g. (3.8, 6) linked to (4,7)), is it possible to visualise/plot this edges between points ?
depending on how your data is organized, you may want to look into plotting with vectors.
For example, if your datafile looks like:
#x1 y1 x2 y2
1 1 3 3
You can plot this using:
set style arrow 1 nohead
plot "my_arrows.dat" using 1:2:($3-$1):($4-$2) with vectors arrowstyle 1
EDIT
Assuming all the points in your datafile are repeated, you can do the following:
set style arrow 1 nohead
plot "my_arrows.dat" using 1:2:($3-$1):($4-$2) with vectors arrowstyle 1,\
"my_arrows.dat" using 1:2 w points
If they're not repeated, you can do:
set style arrow 1 nohead
plot "my_arrows.dat" using 1:2:($3-$1):($4-$2) with vectors arrowstyle 1,\
"my_arrows.dat" using 1:2 w points ls 1 lc rgb "red" pt 1,\
"my_arrows.dat" using 3:4 w points ls 1 lc rgb "red" pt 1
Note that you can play around with the linestyles (linecolor or lc, pointtype or pt, linewidth or lw etc. to make the points appear the same.)
You might not be able to read the line positions in without using a separate utility to generate your plotscript, but the command to draw a line from point to point is
set arrow [X] from first x1,y1 to first x2,y2 nohead
where X is an optional tag number for the arrow, and (x1,y1) and (x2,y2) are points in the graph's coordinate system.

Resources