1 /* Testing Maxima's package draw with Gnuplot
3 * To run this test package, type
4 * demo ("draw_gnuplot.dem") $
11 ("Axes with different styles")$
19 yaxis_color = "#f3b507")$
22 ("Function defined by intervals")$
26 explicit(sin(z),z,2,6),
30 ("Rational function with asymptotes")$
33 key = "y = x^2/(x-2)",
36 explicit(x^2/(x-2),x,-9,15),
40 explicit(x+2,x,-9,15),
42 parametric(2,t,t,-10,20),
46 vector([5.35,2.45],[-1.53,3.25]),
47 vector([-1,7.5],[3,0]),
48 label_alignment = left,
49 label(["y = x+2",6,2.5]),
50 label_alignment = right,
51 label(["x = 2",-1.7,7.5]) ) $
54 ("Functions by name")$
57 H(x) := if x < 0 then x^4 - 1 else 1 - x^5,
59 explicit(F, u, -1, 1),
62 explicit(G, r, -1, 1),
65 explicit(H, s, -1, 1),
66 yrange = [-1.5, 1.5]) )$
69 ("Logarithmic scales")$
75 explicit(exp(x),x,0.1,20),
79 title = "Logarithmic scale")$
82 ("Playing with tics")$
84 xlabel = "User selected tics on axis",
85 ylabel = "Rotated labeled tics",
86 xtics = {-1/2,-1/4,3/4}, /* set of numbers */
87 xtics_axis = true, /* plot tics on x-axis */
88 ytics = {["High",0.75],["Medium",0],["Low",-0.75]},
91 explicit(x^3,x,-1,1) )$
97 [x1,x2]: map('rhs, solve(f1=f2)),
99 title = "Region bounded by two functions",
102 explicit(f1,x,x1,x2),
113 explicit(f2,x,-3,3)) )$
116 ("Complex values in 2D")$
118 explicit(sqrt(x^2-4*x)-x, x, -1, 5),
120 draw_realpart = false,
121 explicit(sqrt(x^2-4*x)-x+2, x, -1, 5) )$
124 ("Complex values in 3D")$
127 explicit(sqrt(x+y),x,-1,1,y,-1,1),
129 draw_realpart = false,
131 explicit(sqrt(x+y)+1,x,-1,1,y,-1,1) )$
139 bars([0.8,5,0.4],[1.8,7,0.4],[2.8,-4,0.4]),
144 bars([1.2,4,0.4],[2.2,-2,0.4],[3.2,5,0.4]),
151 points_joined = true,
152 background_color = orange,
154 proportional_axes ='xy,
158 errors([[1,2,1,2], [3,5,2,1], [10,3,1,1], [17,6,1/2,2]])) $
161 ("Scaling and rotation in 2D")$
162 ( rect : rectangle([0,0],[3,1]),
165 proportional_axes = 'xy,
169 transform = [x*2,-y,x,y],
172 transform = [cos(th)*x - sin(th)*y,
173 sin(th)*x + cos(th)*y, x, y],
177 ("Scaling and reflection in 3D")$
179 mesh([[1,1,3],[7,3,1],[12,-2,4],[15,0,5]],
180 [[2,7,8],[4,3,1],[10,5,8],[12,7,1]],
181 [[-2,11,10],[6,9,5],[6,15,1],[20,15,2]]),
185 transform = [-2*x,-2*y,-2*z,x,y,z],
189 ("Secondary y-scale")$
191 xtics_secondary = auto,
192 ytics_secondary = auto,
193 xaxis_secondary = true,
195 key = "top x, left y",
196 explicit(sin(x),x,0,20),
197 xaxis_secondary = false,
198 yaxis_secondary = true,
200 key = "bottom x, right y",
201 explicit(100*sin(x+0.3)+2,x,0,10)) $
204 ("Regions defined by inequalities")$
209 region( not (x >1 or y > 2+x) and (sin(x+y) > 0) ,x,-20,5,y,-20,5)) $
212 ("Colored axes in 3D")$
214 explicit(x^2+y^2,x,-1,1,y,-1,1),
215 xaxis_width = 2, xaxis_color = orange, xaxis_type = solid, xaxis=true,
216 yaxis_width = 2, yaxis_color = orange, yaxis_type = solid, yaxis=true,
217 zaxis_width = 2, zaxis_color = blue, zaxis_type = solid, zaxis=true,
219 user_preamble= "set xyplane at 0" ) $
222 ("3D surface with mesh lines")$
225 wired_surface = true,
226 explicit(x^2+y^2, x,-2,2,y,-2,2)) $
229 ("Enhanced 3D with logarithmic scale")$
231 title = "Logarithmic scale to colors",
236 palette = [-15,24,-9],
237 explicit(exp(x^2-y^2), x,-2,2,y,-2,2)) $
240 ("Colored 4th dimension")$
243 enhanced3d = sin(x*y),
244 explicit(20*exp(-x^2-y^2)-10, x ,-3, 3, y, -3, 3)) $
247 ("4th dimension in gray")$
254 explicit(5*sin(x*y), x, -5, 5, y, -5, 5),
255 enhanced3d = 5 * sin(v*u),
256 explicit(u^2+v^2+10, u, -5, 5, v, -5, 5))$
259 ("Multiple objects in 3D")$
262 explicit(exp(sin(x)+cos(x^2)),x,-3,3,y,-3,3),
264 parametric(cos(5*u)^2,sin(7*u),u-2,u,0,2),
267 parametric(t^2,sin(t),2+t,t,0,2),
269 title = "Surface & curves",
271 label(["UP",-2,0,3]),
272 label(["DOWN",2,0,-3]) )$
275 ("Parametric surface")$
278 enhanced3d = (1-0.2*cos(v))*sin(u),
280 (1-0.2*cos(v))*cos(u),
281 (1-0.2*cos(v))*sin(u),
283 u, 0, 2*%pi, v, 0, 2*%pi)) $
286 ("Curve with colored 4th dimension")$
291 enhanced3d = (u-1)^2,
292 parametric(cos(5*u)^2,sin(7*u),u-2,u,0,2)) $
295 ("Sinusoidal tube with varying diameter")$
301 tube(cos(a), a, 0, cos(a/10)^2, a, 0, 4*%pi) )$
308 key = "y^2=x^3-2*x+1",
309 implicit(y^2=x^3-2*x+1, x, -4,4, y, -4,4),
311 key = "x^3+y^3 = 3*x*y^2-x-1",
312 implicit(x^3+y^3 = 3*x*y^2-x-1, x, -4,4, y, -4,4),
313 title = "Two implicit functions" ) $
319 implicit(x^2+y^2+z^2=1,x,-1.5,1.5,y,-1.5,1.5,z,-1.5,1.5),
321 implicit(2*x^2+2*y^2=1,x,-1.5,1.5,y,-1.5,1.5,z,-1.5,1.5),
322 surface_hide = true)$
325 ("Colored elevation grid")$
328 makelist(makelist(random(1.0),k,1,5),i,1,5)),
331 wired_surface = true,
332 elevation_grid(m,0,0,3,2)))$
335 ("Colored polygonal line")$
336 (m: makelist([k, k, random(10)],k,1,10),
338 enhanced3d = [sin(j), j],
341 points_joined = true,
346 ("Colored cloud of points")$
347 (m: makelist([random(1.0),random(1.0),random(1.0)],k,1,2000),
349 point_type = filled_circle,
351 enhanced3d = [u+v-w,u,v,w], /* remember that variable names are arbitrary */
355 ("Colored implicit surface")$
357 enhanced3d = [x-y,x,y,z],
358 implicit((x^2+y^2+z^2-1)*(x^2+(y-1.5)^2+z^2-0.5)=0.015,
359 x,-1,1, y,-1.2,2.3, z,-1,1)) $
362 ("Polar coordinates")$
364 dimensions = [400, 400],
365 file_name = "polargrid",
371 title = "Hyperbolic Spiral",
372 polar(10/theta,theta,1,10*%pi) )$
375 ("Spherical coordinates")$
380 spherical(sin(z)*cos(2*a),a,0,2*%pi,z,0,%pi))$
383 ("Cylindrical coordinates")$
391 cylindrical(z,z,-2,2,a,0,2*%pi),
393 cylindrical(3,z,-2,2,az,0,%pi),
395 cylindrical(sqrt(25-z^2),z,-5,5,a,0,%pi) )$
401 explicit(20*exp(-x^2-y^2)-10,x,0,2,y,-3,3),
404 surface_hide = true) $
407 ("Contours in enhanced3d mode")$
408 draw3d(surface_hide =true,
412 explicit(abs((x+y*%i)^3+1),x,-10,10,y,-10,10) ) $
417 title = "Projecting contours",
418 explicit(20*exp(-x^2-y^2)-10,x,0,2,y,-3,3),
421 surface_hide = true) $
426 key = "Sample points",
427 point_type = down_triangle,
429 points(makelist([random(20),random(50)],k,1,10)),
432 points_joined = true,
435 points(makelist(k,k,1,20),makelist(random(30),k,1,20)) )$
438 ("Two samples in 3D")$
439 ( s2 : read_matrix (file_search ("wind.data")),
441 title = "Daily average wind speeds. Two data sets",
444 key = "Sample from stations 1, 2 and 3",
445 points(submatrix (s2, 4, 5)),
448 key = "Sample from stations 1, 4 and 5",
449 points(submatrix (s2, 2, 3))) )$
452 ("Joined and disjoined points")$
456 xyz: [[10,15,12],[11,13,16],[16,10,11],[15,15,15]],
459 point_type = filled_square,
464 points_joined = true,
470 points_joined = impulses,
472 color = "light-blue",
473 points(makelist(exp(-k/10),k,0,50)) )$
478 points_joined = impulses,
480 color = "light-blue",
482 points(makelist([random(10.0),random(10.0),random(10.0)-5],k,0,25)) )$
487 fill_color = "sea-green",
490 polygon([[1,1],[3,0],[4,5],[0,3]]),
493 color = light_yellow,
494 polygon([4,5,7],[6,4,2]),
498 rectangle([-2,-2],[8,-1]),
500 color = dark_goldenrod,
502 rectangle([9,4],[2,-1.5]),
506 ellipse(0,6,3,2,270,-270),
510 ellipse(7,6,2,3,30,-90),
520 vector([1,1],[10,20]),
526 vector([40,5],[-30,30]),
528 color = "midnight-blue",
530 vector([40,40],[-30,-40]))$
533 ("A vector field in 2D")$
534 ( /* vector origins are {(x,y)| x,y=1,...,10} */
535 coord: setify(makelist(k,k,1,10)),
536 points2d: listify(cartesian_product(coord,coord)),
537 /* define the vector field */
538 vf2d(x,y):= vector([x,y],[sin(x),cos(y)]),
539 vect2: makelist(vf2d(k[1],k[2]),k,points2d),
540 draw2d([head_length=0.1, color=blue, unit_vectors=true], vect2))$
543 ("A vector field in 3D")$
544 ( coord: setify(makelist(k,k,1,5)),
545 points3d: listify(cartesian_product(coord,coord,coord)),
546 vf3d(x,y,z):= vector([x,y,z],[sin(x),cos(y),log(z)]),
547 vect3: makelist(vf3d(k[1],k[2],k[3]),k,points3d),
549 append([head_length=0.1, color=blue],
553 ("Multiplot, one column")$
558 parametric(2*cos(t),5*sin(t),t,0,2*%pi)),
563 polygon([4,5,7],[6,4,2])))$
566 ("Multiplot, two columns")$
572 parametric(2*cos(t),5*sin(t),t,0,2*%pi)),
577 polygon([4,5,7],[6,4,2])))$
580 ("Multiplots with arbitrary allocation")$
583 gr2d(explicit(sin(x), x, -1, 1)),
584 gr2d(allocation = [[0.1,0.25], [0.3,0.5]],
586 explicit(x^2, x, -1, 1)),
587 gr2d(explicit(cos(x), x, -1, 1)),
588 gr2d(allocation = [[0.6,0.2], [0.3,0.3]],
590 parametric(u*cos(u),u*sin(u), u, 0, 25)) )$
593 ("Playing with multiplots and background colors")$
595 /* explicit surface in 3d */
597 background_color = yellow,
599 explicit(x^2+y^2, x, -1, 1, y, -1, 1) ),
600 /* explicit curve in 2d */
602 background_color = light_salmon,
603 allocation = [[0, 0],[1/3,1/3]],
604 explicit(x^2, x, -1, 1) ),
605 /* parametric curve in 3d */
607 background_color = cyan,
608 allocation = [[0.6, 0.2],[1/3,2/3]],
609 parametric(u,-u^2,cos(u), u, -1, 1) ) )$
613 ( im: apply('matrix, makelist(makelist(random(200),i,1,30),i,1,30)),
616 image(im,10,10,15,15),
617 image(im,25,25,20,20)) )$
620 ("Matrix of 3D vectors interpreted as an image")$
621 ( rgb: apply('matrix,
624 [random(300),random(300),random(300)],i,1,30),i,1,30)),
625 draw2d(image(rgb,0,0,30,30)) )$
633 rectangle([-28.80,27.53],[34.79,70.26]),
636 geomap(European_Union)) )$
639 ("Lists of options and objects are valid arguments")$
640 ( shadow_explicit(expr, var, vmin, vmax) :=
643 explicit(expr, var, vmin, vmax),
647 explicit(expr, var, vmin, vmax) ],
648 draw2d(shadow_explicit(sin(x),x,0,10)) )$
651 ("Testing enhanced text in Postscript")$
653 file_name = "maxima_draw_demo_1",
654 title = "Made by Maxima during package draw demo",
657 explicit(x^2-x+5, x, 1, 4),
659 explicit(x^2-x+5, x, -1, 5),
660 label(["A = {/Symbol=30 \\362@_{/=9.6 1}^{/=12 4}} ({/Symbol a} x^2 + {/Symbol b} x +{/Symbol g}) d x",1,17]),
666 ("Testing animated gif")$
668 terminal = animated_gif,
670 file_name = "maxima_draw_demo_2",
671 dimensions = [300, 300],
672 makelist(gr2d(explicit(x^(k/10),x,0,1)),k,1,10) )$
675 ("END OF DRAW DEMO") $