I would like to plot the inverse of y=xe^x, with dashed lines leading to the point (-exp(-1), -1)
set parametric
set style arrow 1 head filled size char 1.5,20,50
set arrow 1 from -4.1,0 to 4.1,0 heads
set arrow 2 from 0,-4.1 to 0,4.1 heads
set trange[-4:4]
set xrange[-4:4]
set yrange[-4:4]
set xlabel "x"
set ylabel "y"
unset border
set xtics axis format " "
set ytics axis format " "
plot [-4:0.999] log(1-t)/t, t
plot [-4:4] t*exp(t), t lt rgb "black" title '', -exp(-1),t lt rgb "black", t, -1 lt rgb "black"
I would like to restrict the vertical line to running from y=-1 to y=0, and the horizontal line from x=-exp(-1) to x=0. How can this be done?
Also, is there an easier way to set the line colour for all plots, rather than specifying it for each one?
I see, if I'm understanding it correctly you basically need to annotate your graph with the dashed lines, so why don't you use arrows for the same too.
For example:
# I'm using pngcairo dashed terminal
set terminal pngcairo dashed
set output 'graph.png'
set parametric
set style arrow 1 head filled size char 1.5,20,50
set arrow 1 from -4.1,0 to 4.1,0 heads
set arrow 2 from 0,-4.1 to 0,4.1 heads
#set trange[-4:4]
set xrange[-4:4]
set yrange[-4:4]
set xlabel "x"
set ylabel "y"
unset border
set xtics axis format " "
set ytics axis format " "
#plot [-4:0.999] log(1-t)/t, t
set arrow from -exp(-1),-1 to -exp(-1),0 nohead lt 3
set arrow from -exp(-1),-1 to 0,-1 nohead lt 3
plot [-4:4] t*exp(t),t lt rgb "black" title ''
As far as your questions about line colours is concerned, it is also dependent on the type of terminal that you are using. For instance, with the pngcairo terminal, Gnuplot will itself assign different linestyles to plots. If you want specific colours, then offcourse you have to state them. Take a look at this link. You'll find lots of info with a simple search on Gnuplot's linestyles/linecolour/linetypes etc.
Related
I am trying to plot a simple linear surface of the equation x + y + 2z = 0. This is my file:
set xrange [-4:4]
set yrange [-4:4]
set zrange [-4:4]
set xlabel 'x'
set ylabel 'y'
set zlabel 'z'
set xyplane at -4.0
unset xzeroaxis
unset yzeroaxis
unset zzeroaxis
set border 1023-128
set xtics out nomirror
set ytics out nomirror
set ztics out
set xtics add ('' -4)
set label 1 "{/:Italic x} + {/:Italic y} + 2{/:Italic z} = 0" at 4,4.2,-2 font 'Times New Roman, 11'
set arrow 1 from 0,0,-4 to 0,0,4 filled
set arrow 2 from 0,-4,0 to 0,4,0 filled
set arrow 3 from -4,0,0 to 4,0,0 filled
set arrow 4 from 3.9,4.1,-2.1 to 3.6,3.6,-2.5
unset key
set pm3d lighting primary 0.5 specular 0.6
set style fill transparent solid 1 noborder
set palette defined (0 "cyan", 1 "green")
unset colorbox
set pm3d depthorder
splot -x/2-y/2 with pm3d
The result
I'm using arrows to show the axis, since they seem to be stuck to the xy plane, and moving it causes further issues with the tics and border. But now the problem is that they are completely occluded by the surface. Is there a setting which allows to appear in front when they "pierce" the surface? I'd like to make the surface semitransparent, but the problem is clearer with these settings.
I guess your original idea, i.e. "piercing" a 3D surface with an arrow or line does not work right away in gnuplot, because gnuplot will not calculate the piercing points automatically. Please correct me if I am wrong and let me know in case there might be a simple solution to this.
As you did in your simple case, you can just split the arrow at the origin, because you already know the piercing point. However, what do you do if the surface is irregular or has several piercing points?
Solution: take the effort to create a segmented 3D arrow and let gnuplot automatically show and hide the surfaces as needed. This is probably getting close to what you had in mind. However, this solution will show surprises when you want to change the color of the arrows. So, there is still room for improvement.
Code: (simple version with arrows just along x,y,z axes)
### arrows "piercing" a 3D surface
reset session
set view equal xyz
set xyplane relative 0.0
set xrange [-4:4]
set yrange [-4:4]
set zrange [-4:4]
# create 3D arrow
r = 0.01 # radius of arrow
rHead = 0.1 # radius of arrrowhead
n = 6 # corners of arrow
set print $myArrow
do for [h=-100:90] {
do for [a=360/n:360:360/n] {
print sprintf("%g %g %g",r*cos(a),r*sin(a), h/100.)
}
print ""
}
do for [h=90:100] {
do for [a=360/n:360:360/n] {
print sprintf("%g %g %g",rHead*(100-h)/10.*cos(a), \
rHead*(100-h)/10.*sin(a), h/100.)
}
print ""
}
set print
unset key
unset colorbox
set pm3d depthorder
set samples 100
set isosamples 100
set view 65,46,1.3
# function to demonstrate "piercing"
f(x,y) = (sin(x*3)/x + sin(y*3)/y - 3)/2
splot \
f(x,y) w pm3d, \
$myArrow u 1:2:($3*4):(0) w pm3d lc rgb var, \
$myArrow u 2:($3*4):1:(0) w pm3d lc rgb var, \
$myArrow u ($3*4):1:2:(0) w pm3d lc rgb var
### end of code
Result:
gnuplot> help layer
A gnuplot plot is built up by drawing its various components in a fixed order.
This order can be modified by assigning some components to a specific layer
using the keywords `behind`, `back`, or `front`. For example, to replace the
background color of the plot area you could define a colored rectangle with the
attribute `behind`.
set object 1 rectangle from graph 0,0 to graph 1,1 fc rgb "gray" behind
The order of drawing is
behind
back
the plot itself
the plot legend (`key`)
front
Within each layer elements are drawn in the order
grid, axis, and border elements
pixmaps in numerical order
So basically you need to add the "front" attribute to the objects you want to appear in front of the plot.
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 am trying to draw a figure using some perspective in GNUPLOT. I have already used set xyplane at 0 to add the perspective effect. The problem now is that the tics appear in front of my sphere. For a 3D effect, I want the sphere to obstruct some of the tics, leaving them in the background (the ones on the y and x axis). I tried using set tics back but it doesn't work.
Here is the code:
# set term x11 0
set xlabel 'X'
set ylabel 'Y'
set zlabel 'Z'
set title 'Ray on Sphere 2'
set parametric
set isosamples 50,50
set hidden
set view 120, 200
set view equal
R = 3e-6
set urange [-pi/2:pi/2]
set vrange [0:2*pi]
set xyplane at 0
set xtics back
splot R*cos(u)*cos(v),R*cos(u)*sin(v)-1.5e-6,R*sin(u) w l lc rgb 'yellow' title 'Silica Particle',\
'-' w p title 'Incidence Point'
and the result:
I think your best bet is to move the tic labels to the other side of the plot.
# All as before
set xlabel 'X'
set ylabel 'Y'
set zlabel 'Z'
set title 'Ray on Sphere 2'
set parametric
set isosamples 50,50
set hidden
set view 120, 200
set view equal
R = 3e-6
set urange [-pi/2:pi/2]
set vrange [0:2*pi]
set xyplane at 0
# Now a change in the tic label placement
set xtics offset graph 0, 1.2
set ytics offset graph -1.2, 0
set xlabel offset graph 0, 1.5
set ylabel offset graph -1.5, 0
splot R*cos(u)*cos(v),R*cos(u)*sin(v)-1.5e-6,R*sin(u) w l lc rgb 'yellow' title 'Silica Particle'
I'm sure you can make it nicer by tweaking the placement, the font size, etc
Your view setting is a bit strange for me.
With set view 60,160 it looks like this
One can play with the view interactively and read the setting from the bottom bar.
I have code:
set term eps size 1200,150
set output "output.eps"
set tics out
set xlabel "{/:Italic A} (B)"
set ylabel " "
set ytics nomirror
set xtics nomirror
unset ytics
unset key
#set key tc variable
set label "{/:Bold=12 S}" tc rgb "black" at 54250,5.05
set label "{/:Bold=12 F}" tc rgb "black" at 56170,5.05
set label "{/:Bold=12 R}" tc rgb "black" at 56730,5.05
set arrow from 56000,graph(0,0) to 56000,graph(1,1) nohead dt "-" lw 1 lc rgb "grey30"
set arrow from 56500,graph(0,0) to 56500,graph(1,1) nohead dt "-" lw 1 lc rgb "grey30"
plot 'data.txt' title "{/:Bold T data}" with points pt 7 ps 1 linecolor rgb "black",
and the output.eps has 0kb. What is wrong please? output.png is ok with this code.
Edit
.png - desired
.eps
For some terminals the output file is written when the output is "closed". This can be done by:
calling the command set output after the plot command, you have to call another set output <filename> when you want another plot
closing gnuplot, this works automatically if you write your commands into a scriptfile (for example script.plt) and load your gnuplot script from the shell commandline with gnuplot script.plt
I have the following gnuplot script:
#!/bin/bash
gnuplot << EOF
set term postscript portrait color enhanced
set output 'temp.ps'
set border lw 0.2
unset key
set size 1,1
set origin 0,0
set size ratio 1
set size 0.47,0.47
set mxtics 2; set mytics 4
f(x,z)=z+5-5*log10(x)
set style fill transparent solid 0.1
set yrange [12:-2]; set xrange[0:10000]
plot f(x,17.55) w filledcurve lc rgb "black", \
f(x,17.5) w lines lt 2 lc rgb "green"
EOF
Which gives me an output like this:
I need two fix two things in this image:
1- the filled zone has a black line which delimitates it and this should go away
2- the filling is covering the x and y tics and this should not happen
Thanks!
To address 1):
set style fill transparent solid 0.1 noborder
To address 2):
set grid noxtics nomxtics noytics nomytics front
As a side note, transparent in your set style fill command does nothing in the postscript terminal as it doesn't support solid transparency.