Plotting.red 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. %%%%%%%%%%%%%%%%%%%%%
  2. % PLOTTING
  3. %%%%%%%%%%%%%%%%%%%%%
  4. % Load gnuplot package
  5. load_package gnuplot$
  6. % Plot of sine and cosine
  7. plot(sin(x), title="sin(x) and cos(x)", output="Sine and Cosine");
  8. plot(cos(x), title="sin(x) and cos(x)");
  9. % Superposition of polynomials
  10. plot((x^2+y^2-9)*x*y=0, title="Polynomials", output="Polynomials");
  11. % 3D surface plot
  12. plot(cos sqrt(x**2+y**2),x=(-10 .. 10),y=(-10 .. 10),hidden3d, title="cos sqrt(x^2+y^2)", points=50, output="3D Plot");
  13. % Super-Ellipsoid
  14. on rounded;
  15. ax:=3$
  16. ay:=3$
  17. az:=4$
  18. ns:=4/5$
  19. ew:=1$
  20. for all w,m let c(w,m) = sign(cos(w))*abs(cos(w))**m$
  21. for all w,m let s(w,m) = sign(sin(w))*abs(sin(w))**m$
  22. for all u,v let x(u,v) =ax * c(v, ns)*c(u, ew)$
  23. for all u,v let y(u,v) =ay * c(v, ns)*s(u, ew)$
  24. for all u,v let z(u,v) =az * s(v, ns)$
  25. dd:=pi/15$
  26. w:=for u:=-pi step dd until pi collect
  27. for v:=-pi/2 step dd until pi/2 collect
  28. {x(u,v),y(u,v),z(u,v)}$
  29. gnuplot(set, ticslevel, 0)$
  30. gnuplot(set, xtics, -4, 1, 4)$
  31. gnuplot(set, ytics, -4, 1, 4)$
  32. gnuplot(set, ztics, -4, 1, 4)$
  33. plot (w, hidden3d, title="Super-Ellipsoid", output="Super-Ellipsoid")$
  34. % 3D surface plot with gradients using the
  35. % CAS mode gnuplot operator of the gnuplot
  36. % package. The same plot could be created
  37. % using direct gnuplot commands in Plot
  38. % mode.
  39. plotreset$
  40. gnuplot("unset hidden3d");
  41. gnuplot("unset hidden");
  42. gnuplot("unset surface");
  43. gnuplot("set output ""3D Log""");
  44. gnuplot("set title ""3D Log""");
  45. gnuplot("set samples 30; set isosamples 30");
  46. gnuplot("set pm3d");
  47. gnuplot("set style line 100 lt 5 lw 0.5");
  48. gnuplot("set pm3d hidden3d 100");
  49. gnuplot("set view 57,220");
  50. gnuplot("set xrange [-2:2]");
  51. gnuplot("set yrange [-2:2]");
  52. gnuplot("splot log(x*x*y*y)");
  53. plotshow;
  54. % 3D Torus
  55. % Again, the same plot could be generated
  56. % with direct gnuplot commands in Plot
  57. % mode.
  58. plotreset$
  59. gnuplot("set title ""Interlocking Torus""");
  60. gnuplot("set output ""Torus""");
  61. gnuplot("set parametric");
  62. gnuplot("set urange [-pi:pi]");
  63. gnuplot("set vrange [-pi:pi]");
  64. gnuplot("set isosamples 50,20");
  65. gnuplot("unset key");
  66. gnuplot("unset xtics");
  67. gnuplot("unset ytics");
  68. gnuplot("unset ztics");
  69. gnuplot("set border 0");
  70. gnuplot("set view 60, 30, 1.5, 0.9");
  71. gnuplot("set origin 0.0,-0.075");
  72. gnuplot("set size 0.9, 1.1");
  73. gnuplot("set colorbox vertical user origin 0.9, 0.15 size 0.02, 0.50");
  74. gnuplot("set format cb ""%.1f""");
  75. gnuplot("set pm3d depthorder");
  76. gnuplot("splot cos(u)+.5*cos(u)*cos(v),sin(u)+.5*sin(u)*cos(v),.5*sin(v) with pm3d, 1+cos(u)+.5*cos(u)*cos(v),.5*sin(v),sin(u)+.5*sin(u)*cos(v) with pm3d");
  77. plotshow;