In the following Gnuplot:
set xlabel "Network size, m [r]" font " Helvetica,17"
set ylabel "Algorithms computation time [s]" font "Helvetica,17"
$t500 << EOD
1 0 0 0
2 0.00933135 0.0640543 0.215254
3 0.00954345 0.0746418 0.416871
4 0.009779 0.0853093 0.621712
5 0.0101225 0.0958813 0.822831
6 0.0106212 0.106193 1.02248
7 0.0114236 0.11658 1.22483
8 0.0126996 0.128502 1.42843
9 0.0150443 0.138803 1.62994
10 0.0193814 0.149177 1.83284
11 0.0282591 0.159563 2.0358
12 0.0450926 0.170019 2.24009
13 0.0791815 0.180668 2.44586
14 0.146265 0.191207 2.65134
15 0.284757 0.201806 2.85782
16 0.556054 0.212695 3.0671
17 1.11529 0.223592 3.27625
18 2.22795 0.234535 3.4873
19 4.55297 0.245686 3.69976
20 9.02265 0.257064 3.91294
EOD
set key spacing 1.0
set key top left font "Helvetica, 17"
#set xrange [2:20]
#set yrange [0.001:1000]
set logscale y
set grid
set terminal pdfcairo transparent enhanced
set style function filledcurves y1=0
set ytics ("0" 0.001,"0.01" 0.01,"0.1" 0.1,"1" 1,"10" 10,"100" 100)
unset colorbox
set style fill transparent solid 0.2 border
set bmargin 3.5
set out "program500.pdf"
plot [][] '$t500' using 1:2 title 'S computation' w filledcurves lc rgb "forest-green",\
'$t500' using 1:($2+$3) title 'S computation + Stability computation' w filledcurves lc rgb "violet",\
'$t500' using 1:($2+$4) title 'S computation + Max joint flow computation' w filledcurves lc rgb "gold"
The problem I have is set xrange [2:200] the plot changes and fills the curves upwards, like this,
I would like to know how to keep the filling below the curves as in the first plot with the default ranges and setting xrange [2:20].
"with filledcurves" allows many variants. See the documentation for help filledcurves. The default is with filledcurves closed, which tries to use the points to define a perimeter enclosing a surrounded area. If the curve runs off the edge of the plot, the edges of the plot are used to complete the perimeter. As you found, sometimes the edges chosen by the program are not the ones you wanted.
To control this, use one of the other variants. In this case you probably want with filledcurves y=0, which defines the line at y=0 as part of the perimeter.
... initial lines as above ...
set xrange [2:20]
plot'$t500' using 1:2 title 'S computation' w filledcurves y=0 lc rgb "forest-green",\
'$t500' using 1:($2+$3) title 'S computation + Stability computation' w filledcurves y=0 lc rgb "violet",\
'$t500' using 1:($2+$4) title 'S computation + Max joint flow computation' w filledcurves y=0 lc rgb "gold"
Related
This question already has answers here:
Plotting multiple pm3d surfaces each having its own palettes in gnuplot
(2 answers)
Closed 2 years ago.
I have two 3d surfaces. Is it possible to use a different color palette for each surface with splot?
The script that i used and the graph that is produced follow:
set title "Thermal efficiency versus turbine inlet temperature and degree of superheating diagram"
set termopt enhanced
set grid
set key top left
set xlabel "ΔT_{super} [^{o}C]"
set ylabel "T_{3} [^{o}C]"
set zlabel "n_{th} [-]"
#set datafile missing '0.000000000000000000e+00'
#set datafile missing '0.000000'
set hidden3d
set pm3d
set view 60,60
set palette rgb 7,5,15 #black-blue-red-yellow
splot "para_sub_dtsuper_iso_dtppreg_1.txt" using ($1):($2-273.15):($5) title "Conventional ORC" with lines lt 1 lw 1.5,\
"para_sub_dtsuper_iso_dtppreg_1.txt" using ($1):($2-273.15):($6) title "Regenerative ORC" with lines lt 1 lw 1.5,\
pic_1
On a side not, i would like to know if it is possible to produced mesh color-gradient surfaces like in the picture below:
pic_2
Thank you in advance.
Here is a revised version of the plot that theozh linked to. It shows two surfaces in the same plot, one using color mapping via the built-in palette mechanism and the other effectively doing the same sort of color mapping explicitly. The development version of gnuplot has automated this so that you can construct and use multiple palettes by assigning a name to each one.
#
# Demonstrate construction and use of a separate palette
#
# This method works in 5.2 but requires "lc rgb variable"
# rather than the more natural "fillcolor rgb variable".
# "set pm3d interpolate" breaks the color mapping of this method
#
# This creates a palette equivalent to
# set palette defined (0 "dark-blue", 1 "white")
#
array blues[256]
do for [i=1:256] {
blues[i] = int( (0x7f + (i-1)/(255.) * 0xffff80) );
}
#
# This is the equivalent of
# set cbrange [0:5]
blues_min = 0
blues_max = 5
#
# This function maps z onto a palette color
#
blues(z) = (z <= blues_min) ? blues[1] \
: (z >= blues_max) ? blues[256] \
: blues[ floor(255. * (z-blues_min)/(blues_max-blues_min)) + 1]
F1(x,y) = sqrt(x*y)
F2(x,y) = (x*y)**(1./3)
set samples 41; set isosamples 41
set cbrange [0:5]; set xrange [0:5]; set yrange [0:5]
set palette cubehelix negative
unset colorbox
# Needed for proper occlusion of hidden surface
set pm3d depthorder
# Place a thin border around each facet of the surfaces
set pm3d border lc "black" lw 0.5
set title "Top surface uses hand-constructed 'blues' palette via rgb variable\n".\
"Bottom surface uses 'set palette cubehelix negative'"
set title offset 0,1
splot '++' using 1:2:(F1($1,$2)):(blues(F1($1,$2))) with pm3d lc rgb variable \
title "F1(x,y) using 1:2:3:4 with pm3d lc rgb variable", \
'++' using 1:2:(F2($1,$2)) with pm3d \
title "F2(x,y) using 1:2:3 with pm3d"
I apologize for the delayed response. This is what i was looking for. I am grateful to both of you!
I want to draw something transparent.
my script is :
set output 'rcut.png'
set term png
set style fill transparent solid 0.2 noborder
set style circle radius 1
set multiplot layout 1,3 title "Error of the model"
set xlabel 'batch id'
set logscale xy
set format x "10^{\%T}"
set format y "10^{\%T}"
set key autotitle columnheader
#
set ylabel "Energy[eV]"
p 'rcut=3' u 1:4 w circles lc rgb "navy", 'rcut=6' u 1:4 w circles lc rgb "dark-pink"
#
set ylabel "Force[eV/{\305}]"
p 'rcut=3' u 1:6 w circles lc rgb "navy", 'rcut=6' u 1:6 w circles lc rgb "dark-pink"
#
set ylabel
p 'rcut=3' u 1:8 w circles lc rgb "navy", 'rcut=6' u 1:8 w circles lc rgb "dark-pink"
#
unset multiplot
and it returns an empty plot file:
enter image description here
but when i set the term emf, there will be data in the image:
enter image description here
but it is not what i want, the points are not transparent.
I really want to figure out why,thank you
Long answer:
gnuplot can support two different png terminals, one based on the gd graphics library and selected by set term png and a second one based on the cairo graphics library and selected by set term pngcairo. The gd version only supports transparency if you specify set term png truecolor, which creates an output png file with 24bits of RGB color per pixel and another 8 bits of transparency. Otherwise it generates png files that are smaller (8 bits per pixel) because they are limited to 256 colors and no transparency. The cairo version always produces files with 24bit RGB + 8bit transparency per pixel.
Short answer:
Use either set term pngcairo or set term png truecolor.
Sorry for the long and probably poor title.
I am trying to plot some data in gnuplot, where the data file has the format
x y z
1.0 1.5 0.1
1.3 1.8 0.7
2.1 3.7 1.1
3.1 4.3 1.5
3.7 4.7 1.8
I want to plot y vs. x and, for each point, indicate the value of z by the color of the point. Currently I use the following code for this:
size = 0.5
type = 7
set term pngcairo
set output 'Foo.png'
set palette rgbformulae 22,13,-31
set cblabel "z"
unset key
set xlabel 'x'
set ylabel 'y'
set title 'y vs. x'
plot "Data.txt" u 1:2:3 w p pt type ps size palette
This works, but I would like to make the following change: For each point whose z value is below a cutoff, say 1.0, I want the color to be set to grey, regardless of the z-value. Then for z-values greater than or equal to the cutoff, I want the color to be picked from the palette according to the z-value.
Thus, I want the color to go discontinuously from grey to blue (for the current palette) at the cutoff value. Can this be done, and if so how?
It is difficult to do with a palette based on rgbformulae. It's relatively easy with a defined palette. Here is an example that gives a palette close to what you chose, with a dark gray tacked on at the bottom end. cbrange is then set so that your z cutoff is the minimum. All z values below cbmin will be assigned the endpoint value, which is dark gray in this case.
set xrange [0:1]; set yrange [0:pi]
set sample 100; set isosample 100
set palette defined (-0.01 "grey20", 0 "blue", 0.4 "green", 0.6 "yellow", 1.0 "red")
zmin = -0.6
set cbrange [zmin: *]
set xyplane at zmin
splot cos(x)*sin(y+y*(x*x)) with pm3d
After gnuplot 5.4, this can be achieved by using the function "palette()" in "using" and combining it with the "with point lc rgb variable".
size = 3 ### 0.5 in original code
type = 7
set term pngcairo
set output 'Foo.png'
set palette rgbformulae 22,13,-31
set cblabel "z"
unset key
set xlabel 'x'
set ylabel 'y'
set title 'y vs. x'
set cbrange [0:2] ### this is required by palette() function
gray = 0x808080 ### gray color expressed by integer
plot NaN w p palette, \
"Data.txt" u 1:2:($3<1 ? gray : palette($3)) w p pt type ps size lc rgb variable
The RGB value passed to "lc rgb variable" are determined by comparing $3 with threshold value 1(for example).
"NaN w p palette" is a dummy plot, a technique for forcing the colorbox to appear. Without it, the colorbox will not be displayed.
Here is a gnuplot 5.2 version. You can use a rgbformulae palette.
It uses the datablock $PALETTE which is created after carrying out the command test palette.
Code: (tested with gnuplot as low as 5.2.0)
### cut-off colors for a given rgbformulae palette (gnuplot >=5.2)
reset session
# create some test data
set xrange [-5:5]
set yrange [-5:5]
set samples 50
set isosamples 50
set table $Data
splot (sin(1.3*x)*cos(.9*y)+cos(.8*x)*sin(1.9*y)+cos(y*.2*x))*3
unset table
set palette rgbformulae 22,13,-31
test palette # necessary to put the palette into the datablock $PALETTE
myColorMin = 0
myColorMax = 6
myOutOfRangeColor = 0x808080
myColorPos(c) = int(255.0 * (c-myColorMin)/(myColorMax - myColorMin))+1
myColor(c) = c<myColorMin || c>myColorMax ? myOutOfRangeColor : \
(int(word($PALETTE[myColorPos(c)],2)*0xff)<<16) + \
(int(word($PALETTE[myColorPos(c)],3)*0xff)<<8) + \
(int(word($PALETTE[myColorPos(c)],4)*0xff))
set cbrange [myColorMin:myColorMax]
set view 36, 72
set ztics 5
splot $Data u 1:2:3:(myColor($3)) w pm3d lc rgb variable notitle
### end of code
Result:
I would like to draw an arrow with not a single colour, but a colour gradient along its length. Does anyone know how to achieve that? Some pseudo-code for creating an arrow that starts red and ends blue:
set palette defined (0 "red", 1 "blue")
set cbr [0:1]
set arrow from 0,0 to 1,1 linecolor palette cb [0:1] # this doesn't work
Besides #Friedrich's solution, I would like to suggest a more general solution (although more complicated).
I assume you want to plot something else besides the arrow.
In case your graph needs to use a palette I guess you're in "trouble", because I'm not sure whether gnuplot supports more than one palette in a plot command
(see Gnuplot 5.2 splot: Multiple pm3d palette in one plot call). So, you have to implement the palette for your arrow by yourself (see e.g. Gnuplot: transparency of data points when using palette). If you want to do bent arrows using Cubic Bézier check (https://stackoverflow.com/a/60389081/7295599).
Code:
### arrow with color gradient (besides other palette in plot)
reset session
array A[4] = [-4,-2,4,2] # arrow coordinates x0,y0,x1,y1
Ax(t) = A[1] + t*(A[3]-A[1])
Ay(t) = A[2] + t*(A[4]-A[2])
AColorStart = 0xff0000 # red
AColorEnd = 0x0000ff # blue
r(c) = (c & 0xff0000)>>16
g(c) = (c & 0x00ff00)>>8
b(c) = (c & 0x0000ff)
AColor(t) = ((int(r(AColorStart)*(1-t)+r(AColorEnd)*t))<<16) + \
((int(g(AColorStart)*(1-t)+g(AColorEnd)*t))<<8) + \
int(b(AColorStart)*(1-t)+b(AColorEnd)*t)
array AHead[1] # dummy array for plotting a single point, here: arrow head
set angle degrees
set style arrow 1 lw 3 lc rgb var size 0.5,15 fixed
set palette grey
plot '++' u 1:2:($1*$2) w image notitle, \
[0:0.99] '+' u (Ax($1)):(Ay($1)):(AColor($1)) w l lw 3 lc rgb var notitle,\
AHead u (Ax(0.99)):(Ay(0.99)):(Ax(1)-Ax(0.99)):(Ay(1)-Ay(0.99)):(AColor($1)) w vec as 1 notitle
### end of code
Result:
Addition:
For what it is worth, here is a variation which allows plotting of multiple arrows each with a different palette. I guess it requires gnuplot 5.2, because of indexing the datablock $PALETTE[i].
Code:
### multiple arrows each with different color gradients (besides other palette in plot)
reset session
# define palettes
set print $myPalettes
test palette # get default palette into datablock $PALETTE
print $PALETTE # add palette to $myPalettes
set palette rgb 33,13,10 # define next palette
test palette # get palette into datablock $PALETTE
print $PALETTE # add palette to $myPalettes
set palette defined (0 "blue", 1 "black", 2 "red") # define next palette
test palette # get palette into datablock $PALETTE
print $PALETTE # add palette to $myPalettes
set print
ColorComp(p,t,c) = int(word($myPalettes[p*257+int(255*t)+1],c+1)*0xff)
AColor(p,t) = (ColorComp(p,t,1)<<16) + (ColorComp(p,t,2)<<8) + ColorComp(p,t,3)
set size ratio -1
set angle degrees
unset key
set style arrow 1 lw 3 lc rgb var size 0.5,15 fixed
array AHead[1] # dummy array for plotting a single point, here: arrow head
set palette grey # yet another palette for the background
# x0 y0 x1 y1 paletteNo
$Arrows <<EOD
-4 -4 4 0 0
-4 -2 4 2 1
-4 0 4 4 2
EOD
Ax(i,t) = word($Arrows[i],1) + t*(word($Arrows[i],3)-word($Arrows[i],1))
Ay(i,t) = word($Arrows[i],2) + t*(word($Arrows[i],4)-word($Arrows[i],2))
Palette(i) = int(word($Arrows[i],5))
plot '++' u 1:2:($1*$2) w image, \
for [i=1:|$Arrows|] [0:0.99:0.01] '+' u (Ax(i,$1)):(Ay(i,$1)):(AColor(Palette(i),$1)) w l lw 4 lc rgb var, \
for [i=1:|$Arrows|] AHead u (Ax(i,0.99)):(Ay(i,0.99)): \
(Ax(i,1)-Ax(i,0.99)):(Ay(i,1)-Ay(i,0.99)):(AColor(Palette(i),$1)) w vec as 1
### end of code
Result:
With line palette one can color-code a line. With a second command one could set the head, via set arrow or with a plot vector command
set palette defined (0 "red", 1 "blue")
set cbr [0:1]
set arrow 1 from 0.9,0.9 to 1,1 lc "blue"
plot sample [t=0:1] "+" us (t):(t):(t) w l palette
Thus two commands are necessary. The head of the arrow has single colour, which you have to specify.
I'm solving the pendulum's equation of motion, and I need to create an animation in GNUplot that shows the evolution of the system.
R4K provides me with the solution point by point, and this solution is stored in a .dat file named 'd' in columns 2 and 3. These are the orders given to GNUplot:
set xrange [-2:2]
set yrange [-2:2]
set pointsize 2
set style line 2 lc rgb '#0060ad' pt 7
set object circle at first 0,0 size scr 0.01 \
fillcolor rgb 'black’ fillstyle solid
do for [ii=1:3762] {
plot 'd.dat' using 2:3 every ::ii::ii linestyle 2
pause 0.002
}
I now want to connect the circle in [0,0] to the moving point plotted from d.dat with a moving line; how can I do it? I found a solution (kind of) here, but still I don't know how to tell GNUplot to search for a certain point in 'd.dat', different every time, and to draw the line between it and the centre.
The solution of user8153 is so far the best. Let me give a trial. If I were you I would have use arrows that update their positions with the moving end dynamically, since the every command loads one point at time. GNUPLOT provides environment variables such as GPVAL_X_MIN, GPVAL_X_MAX, GPVAL_Y_MIN,... that can be useful:
set xrange [-2:2]
set yrange [-2:2]
set pointsize 2
set style line 2 lc rgb '#0060ad' pt 7
set object circle at first 0,0 size scr 0.01 \
fillcolor rgb 'black’ fillstyle solid
do for [ii=1:3762] {
plot 'd.dat' using 2:3 every ::ii::ii linestyle 2
# makes GPVAL_ variables available
xpos = GPVAL_X_MIN; ypos = GPVAL_Y_MIN # or MAX does not matter since you are
# loading one point at time.
unset arrow # Remove the one of the previous graph
set arrow from 0, 0 to xpos, ypos nohead lc rgb 'black'
replot
pause 0.002
}
I have no data to debug this code snippet, but I would have done something along this line. Later versions of GNUPLOT allow to use stats command that avoids replot (replot could have an effect here on the persistence of images of the film but I am not sure). You can also try something along the line
set xrange [-2:2]
set yrange [-2:2]
set pointsize 2
set style line 2 lc rgb '#0060ad' pt 7
set object circle at first 0,0 size scr 0.01 \
fillcolor rgb 'black’ fillstyle solid
do for [ii=1:3762] {
stats 'd.dat' using 2:3 every ::ii::ii # applied the statistical summary of
# the data file
xp = STATS_min_x; yp = STATS_min_y
unset arrow
set arrow from 0, 0 to xp, yp nohead lc rgb 'black'
plot 'd.dat' using 2:3 every ::ii::ii linestyle 2
pause 0.002
}
I have never used STATS with the every command (let me know the output just for fun).
Hope that helps