I have generated this picture with Gnuplot, shortly by means the flags below for the palette and plot:
set palette defined ( 0 "green", 1 "blue", 2 "blue", 3 "orange" )
plot "10steps_500" u 1:2:3 w p pt 7 ps 2.0 lt pal, "10steps_500-300" u 1:2:3 w p pt 7 ps 2.0 lt pal
However, I wanna bring the blue point to front. Someone knows how can we do it in gnuplot?
You need to first plot the green points, and then the others afterwards. It looks like you get the color information from the third column in your data files, so something like this should work:
plot "10steps_500" u 1:($3 == 0 ? $2 : 1/0):3 w p pt 7 ps 2.0 lt pal, \
"" u 1:($3 != 0 ? $2 : 1/0):3 w p pt 7 ps 2.0 lt pal
This first line plots all the points for which the value in the third column is 0, and the second line plots all the other points.
Related
basically I would like to reproduce the filling styles in the following image in gnuplot:
I tried using the common pattern with filledcurves but none of the patterns is similar to those in the picture. Is there a way to get this type of patterns (note the filled area is not solid) in gnuplot ?
Thank you.
Check help filledcurves and set the color to transparent according to the scheme 0xAARRGGBB.
Code:
### semitransparent fill between curves
reset session
# create some random test data
set print $Data1
do for [x=1:100] { print sprintf("%g %g %g %g",x,5*cos(x/7.)+rand(0),rand(0)+0.3,rand(0)+0.3) }
set print
set print $Data2
do for [x=1:100] { print sprintf("%g %g %g %g",x,3*sin(x/9.)+rand(0),rand(0)+0.3,rand(0)+0.3) }
set print
unset key
plot $Data1 u 1:2 w l lc "red", \
'' u 1:($2-$3):($2+$4) w filledcurve lc rgb 0xeeff0000, \
$Data2 u 1:2 w l lc "blue", \
'' u 1:($2-$3):($2+$4) w filledcurve lc rgb 0xee0000ff
### end of code
Result:
Addition: (workaround for vertical dashed "fill")
To be honest, (as in your case) if you have to zoom in very close to see the difference between a semitransparent fill and a "fill" with vertical lines, then I'm not sure whether this is really necessary.
Anyway, here is a workaround for a "fill" of vertical dashed lines. This is realized with vectors and dashed lines dt 1 (=solid), dt 2 (=dashed), dt 3 (=dotted). However, this is not a real fill but requires enough regular (here: 1000) data points to give this impression. It also depends on transparency of the linecolor and the size of the graph. If you don't have enough regular datapoints you could resample your data, however, this is not straightforward in gnuplot (see: Resampling data with gnuplot),
This still doesn't look identical to your example but comes somewhat closer.
Code:
### special "fill" with dashed vertical lines
reset session
# create some random test data
set table $Data1
set samples 1000
plot [1:100] '+' u (x):(3*cos(x/5.)):(rand(0)*0.5+0.3):(rand(0)*0.5+0.3) w table
set table $Data2
set samples 1000
plot [1:100] '+' u (x):(5*sin(x/7.)):(rand(0)*0.5+0.3):(rand(0)*0.5+0.3) w table
set table $Data3
set samples 1000
plot [1:100] '+' u (x):(7*sin(x/9.)):(rand(0)*0.5+0.3):(rand(0)*0.5+0.3) w table
unset table
unset key
plot $Data1 u 1:2 w l lc "red", \
'' u 1:($2-$3):(0):(1) w vectors lc rgb 0xddff0000 dt 1 nohead, \
$Data2 u 1:2 w l lc "green", \
'' u 1:($2-$3):(0):($4+$3) w vectors lc rgb 0xdd00ff00 dt 2 nohead, \
$Data3 u 1:2 w l lc "blue", \
'' u 1:($2-$3):(0):($4+$3) w vectors lc rgb 0xdd0000ff dt 3 nohead
### end of code
Result:
Zoomed-in to show the dashed lines:
I Have a dataset with a whole bunch of rows corresponding to points (x,y) on the plane. I want to plot this collection of points with a gradient so the first point in the list is blue, and as it plots more and more points from the list it shifts to red.
Is there any way to do this in gnuplot? Any advice would be appreciated.
You can use the linecolor palette z option to do this. For example, if you have a datafile test.dat that looks like
1 1
2 2
3 3
4 4
then you can do
unset key
set palette defined ( 0 "blue", 1 "red" )
plot "test.dat" u 1:2:0 w p pt 7 ps 3 lc palette z
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:
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:
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