Wayne  Tsai Wayne Tsai - 4 months ago 9
Linux Question

GNU plot: How to plot a sphere and imported file on the same frame?

I am very new to GNU plot. Now, I am trying to plot a sphere and imported

.txt
file at the same frame. However, I cannot figure out a suitable way. Here are my attempts:


  1. Using only
    splot
    .

    set parametric ; unset pm3d ; splot [-pi:pi] [-pi/2:pi/2] cos(u)*cos(v), cos(u)*sin(v), sin(u) ; unset parametric ; splot "traj_3dtest.txt" u 2:3:4


    But there is only
    splot "traj_3dtest.txt" u 2:3:4
    in output file.

  2. Using
    multiplot


    set parametric
    splot cos(u)*cos(v), cos(u)*sin(v), sin(u)
    splot "traj_3dtest.txt" u 2:3:4


    But the output shows that overlapped two plot, prnt_scrn_1



Here are also extra question: how to plot the spherical "surface"? I mean, I don't want a sphere with contours but a gray surface.

NOTE: the data file format

# T X Y Z Vx Vy Vz
1.00 -0.429 -0.847 0.314 -.09755 -.29510 -.15748
2.00 -0.429 -0.848 0.314 -.09752 -.29504 -.15750
3.00 -0.429 -0.848 0.313 -.09749 -.29497 -.15752
4.00 -0.429 -0.848 0.313 -.09746 -.29491 -.15755

Answer

If you want both in the same frame, but not overlapping:

splot cos(u)*cos(v), cos(u)*sin(v), sin(u), "traj_3dtest.txt" u 2:3:4

From your multiplot example, you'd have the two plots with separate axis:

set multiplot layout 2,1
splot cos(u)*cos(v), cos(u)*sin(v), sin(u)
splot "traj_3dtest.txt" u 2:3:4

or

set multiplot

set origin 0,0.5
set size 1,0.5
splot cos(u)*cos(v), cos(u)*sin(v), sin(u)

set origin 0,0
set size 1,0.5
splot "traj_3dtest.txt" u 2:3:4
Comments