How do I plot a white spherical surface? In three dimensions, radius should be 1, center at the origin.
I have scattered point data on the sphere. It is hard to look at it, since the points from the opposite end of the sphere are just as visible. Therefore I would like to create a white spherical "background" on top of which the data is clearly visible.
Restricting the range of one coordinate axis to [0:1] is cumbersome since it cuts off half the points at which I also want to look.
Tanks!
Here is an example, borrowed from the gnuplot demo page. For a white sphere, replace yellow with white:
set parametric
set isosamples 50,50
set hidden
R = 1. # radius of sphere
set urange [-pi/2:pi/2]
set vrange [0:2*pi]
splot R*cos(u)*cos(v),R*cos(u)*sin(v),R*sin(u) w l lc rgb "yellow", \
"-" w p
1 0 0
-1 0 0
e
You can see that only one of the two data points is visible, while the other is hidden behind the sphere.
Related
I want to draw an ellipse with gnuplot. It should be slightly tilted, hence I use the angle option.
But the angle messes with the size of the ellipse. Am I getting something wrong in the docu?
See the following example:
set output "test.pdf"
set obj ellipse center 5,0.5 size 4,0.2 angle 20
set xrange [0:10]
plot sin(x)
The added two png's show my results. I use version 5.2.8.
If you want the proportions of the ellipse to remain constant after rotation you must give the major and minor diameters in the same units, e.g. "units xx" or "units yy". Here I define the ellipse in terms of a 4:1 ratio of major:minor axis using x coordinates.
set obj 1 ellipse center 5,0.5 size 4,1 fs empty bo lc "blue" angle 0 units xx
set obj 2 ellipse center 5,0.5 size 4,1 fs empty bo lc "red" angle 20 units xx
set obj 3 ellipse center 5,0.5 size 4,1 fs empty bo lc "green" angle 40 units xx
set xrange [0:10]
plot sin(x)
Edit: Ethan's solution is certainly the way to go.
Just keep in mind, if you don't have set size ratio -1, a line, e.g. like plot x will not appear in a 45° degree angle to the x-axis.
Probably, the simplest solution would be to set size ratio -1 to have the same scale for x and y-axis. If you need different scale there should be a different solution.
Code:
### draw tilted ellipse with same proportions
reset session
set size ratio -1
set obj 1 ellipse center 5,0.5 size 4,0.2 angle 0 fc "red"
set obj 2 ellipse center 5,0.5 size 4,0.2 angle 20 fc "green"
set obj 3 ellipse center 5,0.5 size 4,0.2 angle 45 fc "blue"
set obj 5 ellipse center 5,0.5 size 4,0.2 angle 90 fc "magenta"
set xrange [0:10]
set yrange [-3:3]
plot sin(x)
### end of code
Result:
If the output to a dummy file is allowed, how about the following solution.
set terminal pdf size 10cm,10cm
set xrange [0:10]
# dummy plotting
set output "dummy.pdf"
plot sin(x)
factor = real(GPVAL_X_MAX - GPVAL_X_MIN)/real(GPVAL_Y_MAX-GPVAL_Y_MIN) \
* real(GPVAL_TERM_YMAX - GPVAL_TERM_YMIN)/real(GPVAL_TERM_XMAX - GPVAL_TERM_XMIN)
# real plotting
set output "test.pdf"
set obj ellipse center 5,0.5 size 4,factor*0.2 angle 20 unit xx
replot
In this script, the ratio of visible unit length between x and y axis is calculated using from variable GPVAL_* determined by the dummy plotting. Multipling it to vertical axis of the ellipse and using 'unit xx' as same as Ethan's answer, you may get the figure that you want.
If you are on UNIX(-like) system, replace 'set output "dummy.pdf"' as,
set output "/dev/null"
I haven't been able to find any example of what I'm trying to do in GNUplot from raking docs and demos.
Essentially I want to plot the Blue, Green, and Red lines I manually drew on this output (for demonstration) at the 10/50/90% marks.
EDIT: For clarity, I'm looking to determine where the distribution lines hit the cumulative distribution at 0.1/0.5/0.9 to know which co-ordinates to draw the lines at. Thanks!
set terminal png size 1600,800 font "Consolas" 16
set output "test.png"
set title "PDF and CDF - 1000 Simulations"
set grid y2
set ylabel "Date Probability"
set y2range [0:1.00]
set y2tics 0.1
set y2label "Cumulative Distribution"
set xtics rotate by 90 offset 0,-5
set bmargin 6
plot "data.txt" using 1:3:xtic(2) notitle with boxes axes x1y1,'' using 1:4 notitle with linespoints axes x1y2
Depending on the number of points in your cumulative data curve you might need interpolation. The following example is chosen such that no original data point will be at your levels 10%, 50%, 90%. If your data is not steadily increasing, it will take the last value which matches your level(s).
The procedure is as follows:
plot your data to a dummy table.
check when Level is between to successive y-values (y0,y1).
remember the interpolated x-value in xp.
draw arrows from the borders of the graph to the point (xp,Level) (or instead use the partly outside rectangle "trick" from #Ethan).
Code:
### linear interpolation of data
reset session
set colorsequence classic
set key left
# create some dummy data
set sample 10
set table $Data
plot [-2:2] '+' u 1:(norm(x)) with table
unset table
Interpolate(yi) = x0 + (x1-x0)*(yi-y0)/(y1-y0)
Levels = "0.1 0.5 0.9"
do for [i=1:words(Levels)] {
Level = word(Levels,i)
x0 = x1 = y0 = y1 = NaN
set table $Dummy
plot $Data u (x0=x1,x1=$1,y0=y1,y1=$2, (y0<=Level && Level<=y1)? (xp=Interpolate(Level)):NaN ): (Level) w table
unset table
set arrow i*2 from xp, graph 0 to xp,Level nohead lc i
set arrow i*2+1 from xp,Level to graph 1,Level nohead lc i
}
plot $Data u 1:2 w lp pt 7 lc 0 t "Original data"
### end code
Result:
It is not clear if you are asking how to find the x-coordinates at which your cumulative distribution line hits 0.1, 0.5, 0.9 (hard to do so I will leave that for now) or asking how to draw the lines once you know those x values. The latter part is easy. Think of the lines you want to draw as the unclipped portion of a rectangle that extends off the plot to the lower right:
set object 1 rectangle from x1, 0.1 to graph 2, -2 fillstyle empty border lc "blue"
set object 2 rectangle from x2, 0.1 to graph 2, -2 fillstyle empty border lc "green"
set object 3 rectangle from x3, 0.1 to graph 2, -2 fillstyle empty border lc "red"
plot ...
There are plenty of resources online to teach you how to draw 2d plots with broken axis, e.g. http://www.phyast.pitt.edu/~zov1/. Basically what strategy used was to draw two plots using multiplot mode, and combine them together.
However, what I wished to do is to break the Z axis, consider these two surfaces:
Because of the large energy gap between two surfaces, the ground energy surface is almost "flat" in this plot, yet if we plot the ground energy surface alone, we can see it is not "flat" at all:
Is there a way of breaking the Z axis to make Gnuplot display more details of the surface? multiplot does not work here because it is a 3d plot.
You can shift the upper surface downwards and relabel the z tics manually. Take this figure as an example:
Let's work out some gnuplot magic:
# Make sure that there are no data points exactly at the corners
# of the xy plane (it affects the vertical borders)
set xrange [-1.001:1.001]
set yrange [-1.001:1.001]
zmin = -2
zmax = 5
dz = zmax - zmin
set zrange [zmin:zmax]
# Remove vertical borders
set border 15
# Some functions to plot
f(x,y)=x**2+y**2+10.
g(x,y)=-x**2-y**2
# Draw vertical borders by hand leaving empty space where the
# axis is broken. I have used variables zmin etc. for transparency
set for [i=-1:1:2] for [j=-1:1:2] arrow \
from i,j,zmin-dz*0.5 to i,j,1 lw 1 nohead
set for [i=-1:1:2] for [j=-1:1:2] arrow \
from i,j,2 to i,j,zmax lw 1 nohead
# Draw zig-zag line to denote broken axis
set for [i=-1:1:2] for [j=-1:1:2] arrow \
from i,j,1 to i-0.05,j,1+0.25 lw 1 nohead
set for [i=-1:1:2] for [j=-1:1:2] arrow \
from i-0.05,j,1+0.25 to i+0.05,j,1+0.75 lw 1 nohead
set for [i=-1:1:2] for [j=-1:1:2] arrow \
from i+0.05,j,1+0.75 to i,j,2 lw 1 nohead
# Add ztics by hand. Use "for" if you have many tics
set ztics (-2, 0)
# We print the z value - 7, which is the amount we are shifting the
# upper surface
set ztics add ("10" 3, "12" 5)
# Plot shifting the surface
splot f(x,y)-7, g(x,y)
Note that the new borders defined with set arrow will be drawn behind the surface. If you want a particular one to be in the front, then take it out of the set for loop and add the front keyword to it.
I would like to shade a specific region in a polar plot using GNUPlot. This region is bounded by limits in R (r1, r2) and Theta (t1, t2), so the final shape is an annulus segment defined by only 4 points in polar space.
In a Cartesian plot, it is quite easy to draw a rectangle, either by (set object rect) or filledcurve of a closed shape with 4 vertices. However, a filledcurve shape specified by 4 points in a polar plot still results in a quadrilateral (lines with constant R should be circular arcs, not straight lines).
Is there a simple or straightforward way to plot this shape in polar coordinates? I've tried using two arcs and then filling the space between them, but this has not been working correctly so far and I'm not sure if there's a better way to go about this.
Unfortunately, that is not too easy. You can set a circle object for which you specify the begin and end angles. To cut out the center part you must draw a second white circle above:
set xrange [-1:1]
set yrange [-1:1]
set size ratio -1
r1 = 0.5
r2 = 1
theta1 = -30
theta2 = 60
set angles degrees
set style fill solid noborder
set object circle at first 0,0 front size r2 arc [theta1:theta2] fillcolor lt 1
set object circle at first 0,0 front size r1 fillcolor rgb 'white'
plot -10 notitle
Here it is essential, that x and y axis have the same unit (set size ratio -1), because a circle object is defined in units of the first x-axis and does not respect the y-axis at all. If you don't have anything else to plot, you must use a plot command which plots something outside of the defined ranges. Without a plot the objects aren't drawn.
The result with 4.6.5 is:
With the upcoming 5.0 version you can use pseudo-data (with the special file name +) together with the filledcurves plotting style:
r1 = 0.5
r2 = 1.0
theta1 = 20
theta2 = 135
set polar
set angles degrees
set size ratio -1
unset raxis
unset rtics
set trange [theta1:theta2]
set style fill solid noborder
plot '+' using 1:(r1):(r2) with filledcurves notitle
I plot a data file containing 2 columns as a line. I also have data ranges for the x axis that I would like to use to color the background.
For example, in the data range from 41 to 70, I would like to color the background blue.
I know that these commands can color background but I haven't yet figured out how to use x values :
set obj 1 rectangle behind from graph 0, graph 0 to graph 1, graph 1
set obj 1 fillstyle solid 1.0 fillcolor rgb "blue"
Gnuplot supports multiple coordinate systems. As your already aware, there's graph where 0,0 is the lower left corner of the graph and 1,1 is the upper right corner of the graph. There's also screen. (0,0 is the lower left corner of the "screen"). The axes you're looking for is first. Note that you can even mix coordinate systems. the point first 50, graph 0 is at the bottom of the graph at the point 50 on the x axis. Putting this all together, you should be able to set your rectangle as:
set obj 1 rectangle behind from first 41, graph 0 to first 70, graph 1 back
set obj 1 fillstyle solid 1.0 fillcolor rgb "blue"
I also added "back" to the command so that the rectangle is drawn behind all the other plot elements