Search code examples
plotgnuplottikz

Plotting points on a sphere with gnuplot


I have a data file with a set of points (x,y,z) that are restricted to the surface of a sphere. I would like to plot them, but I wouldn't like all the points to appear on the plot, only the ones visible in 3d. My idea is to draw a solid sphere in order to hide the points from the back. I tried following this answer, but first, if I plot in pdf I get this.

enter image description here

Second, I would like to plot the points as dots with pt7 or something small, but in the gnuplot qt viewer there is still a white wireframe, as seen:

enter image description here

I would like to achieve something similar to this:

enter image description here

How can I remove this wireframe? If someone knows a simpler way to do this with pgfplots, tikz or other software it would also suffice me.


Solution

  • A possible solution could be the following:

    1. Generate xyz-data for a prototype sphere with radius R
    2. plot the sphere data with invisible lines (lt -2) and set hidden3d
    3. plot your xyz points, here as demo world.dat.

    Maybe I'm thinking to complicated and there are simpler solutions. I used an animated version to "illustrate" the hidden points. I hope you can adapt the code to your needs.

    Code:

    ### points on sphere partly hidden
    reset session
    set view equal xyz
    set xyplane relative 0
    R = 1
    unset tics
    unset border
    
    # sphere prototype data
    set parametric
    set isosamples 24
    set samples 24
    set urange [0:2*pi]
    set vrange [-pi/2:pi/2]
    set table $Sphere
        splot R*cos(u)*cos(v), R*sin(u)*cos(v), R*sin(v)
    unset table
    unset parametric
    
    # convert "world.dat" data into x,y,z coordinates
    # file can be found in directory gnuplot/demo
    set angle degrees
    set table $World
        plot "world.dat" u (R*cos($1)*cos($2)):(R*sin($1)*cos($2)):(R*sin($2)) w table
    unset table
    
    set hidden3d
    set term gif animate size 400,400 delay 20 optimize
    set output "tbWorldInDots.gif"
    
    N = 36
    do for [i=N:1:-1] {
        set view 90,360./N*i,1.8
        splot \
            $Sphere u 1:2:3 w l lt -2 notitle , \
            $World u 1:2:3 w p pt 7 ps 0.5 lc rgb "black" notitle, \
    }
    set output
    ### end of code
    

    Result:

    enter image description here