/* file plot2dtest.mac Dec. 2017 Ted Woollett Maxima by Example http://web.csulb.edu/~woollett This is a batch file: use batch(plot2dtest) to run. */ "-----------------------------------------"$ "1. test default number-color association with [style, [lines,6]] syntax "$ " expect: 1 = blue, 2 = red, 3 = green"$ " 4 = majenta, 5 = black, 6 = cyan, 7 = blue, 8 = red, ..."$ /* A draw2d version of the following plot2d plot is (You only need to load the draw package once per session.) load(draw); draw2d (points_joined = true, line_width = 4,point_size=0, xrange = [-2,20], yrange = [-2,8], color=blue, key = "1", points ([[0,0],[0,5]]), color=red, key = "2",points ([[2,0],[2,5]]), color = green, key = "3", points ([[4,0],[4,5]]), color = magenta, key = "4", points ([[6,0],[6,5]]), color = black, key = "5",points ([[8,0],[8,5]]), color = cyan, key = "6",points ([[10,0],[10,5]]), color = blue, key = "7",points ([[12,0],[12,5]]), color = red, key = "8",points ([[14,0],[14,5]]), xtics = none,ytics = none,axis_bottom = false, axis_top = false,axis_left = false,axis_right = false)$ */ plot2d( [ [discrete,[[0,0],[0,5]]], [discrete,[[2,0],[2,5]]], [discrete,[[4,0],[4,5]]],[discrete,[[6,0],[6,5]]], [discrete,[[8,0],[8,5]]],[discrete,[[10,0],[10,5]]], [discrete,[[12,0],[12,5]]],[discrete,[[14,0],[14,5]]] ], [style, [lines,6]], [x,-2,20], [y,-2,8], [legend,"1","2","3","4","5","6","7","8"], [xlabel," "], [ylabel," "], [box,false],[axes,false])$ "-----------------------------------------"$ " 2. test number-color association in plot2d using [lines, nwidth, ncolor] syntax. "$ plot2d( [ [discrete,[[0,0],[0,5]]], [discrete,[[2,0],[2,5]]], [discrete,[[4,0],[4,5]]],[discrete,[[6,0],[6,5]]], [discrete,[[8,0],[8,5]]],[discrete,[[10,0],[10,5]]], [discrete,[[12,0],[12,5]]],[discrete,[[14,0],[14,5]]] ], [style, [lines,6,1],[lines,6,2],[lines,6,3], [lines,6,4],[lines,6,5],[lines,6,6],[lines,6,7], [lines,6,8]], [x,-2,20], [y,-2,8], [legend,"1","2","3","4","5","6","7","8"], [xlabel," "], [ylabel," "], [box,false],[axes,false])$ "-----------------------------------------"$ " 3. test colors with [style,[lines,6]], [color, c1, c2, ...] syntax"$ /* A draw2d version of the following plot2d plot is: (You only need to load the draw package once per session.) load(draw); draw2d (points_joined = true, line_width = 4,point_size=0, xrange = [-2,20], yrange = [-2,8], color=blue, key = "blue", points ([[0,0],[0,5]]), color=red, key = "red",points ([[2,0],[2,5]]), color = green, key = "green", points ([[4,0],[4,5]]), color = magenta, key = "magenta", points ([[6,0],[6,5]]), color = black, key = "black",points ([[8,0],[8,5]]), color = cyan, key = "cyan",points ([[10,0],[10,5]]), color = blue, key = "blue",points ([[12,0],[12,5]]), color = red, key = "red",points ([[14,0],[14,5]]), xtics = none,ytics = none,axis_bottom = false, axis_top = false,axis_left = false,axis_right = false)$ */ plot2d( [ [discrete,[[0,0],[0,5]]], [discrete,[[2,0],[2,5]]], [discrete,[[4,0],[4,5]]],[discrete,[[6,0],[6,5]]], [discrete,[[8,0],[8,5]]],[discrete,[[10,0],[10,5]]], [discrete,[[12,0],[12,5]]],[discrete,[[14,0],[14,5]]] ], [style,[lines,6]], [color, blue, red, green, magenta, black, cyan,blue,red], [x,-2,20], [y,-2,8], [legend,"blue","red","green","magenta","black","cyan","blue","red"], [xlabel," "], [ylabel," "], [box,false],[axes,false])$ "-----------------------------------------"$ " 4. test default number-(point type) association with [style,[points,5,1]], syntax."$ " Ideally, there should be 13 distinct point types, but recent Maxima"$ " versions of Xmaxima only give 6 using either Windows 7 or Windows XP."$ /* One can also use numbers to choose point types using draw2d; there are 16 point types if we include dot (0) as a point type. The corresponding names are given incorrectly in the Maxima manual under the topic 'point_type' in the draw section of the manual. Note that plot2d also has a syntax involving the plot_type, as in [plot_type, bullet,circle,...]. draw2d ( xrange = [-0.2,1], yrange = [-0.2,0.7], color = blue, point_size = 2, point_type = 0, key = "0", points([[-0.1,0.5]]), point_type = 1, key = "1", points([[0,0.5]]), point_type = 2, key = "2", points ([[0.1,.5]]), point_type = 3, key = "3", points ([[0.2,.5]]), point_type = 4, key = "4", points ([[0.3,.5]]), point_type = 5, key = "5", points ([[0.4,0.5]]), point_type = 6, key = "6", points ([[0.5,.5]]), point_type = 7, key = "7", points ([[0.6,.5]]), point_type = 8, key = "8", points ([[0.7,.5]]), point_type = 9, key = "9", points ([[0,0]]), point_type = 10, key = "10", points ([[0.1,0]]), point_type = 11, key = "11", points ([[0.2,0]]), point_type = 12, key = "12", points ([[0.3,0]]), point_type = 13, key = "13", points ([[0.4,0]]), point_type = 14, key = "14", points ([[0.5,0]]), point_type = 15, key = "15", points ([[0.6,0]]), point_type = 16, key = "16", points ([[0.7,0]]), xtics = none,ytics = none,axis_bottom = false, axis_top = false,axis_left = false,axis_right = false)$ */ plot2d([ [discrete,[[0,.5]]],[discrete,[[0.1,.5]]],[discrete,[[0.2,.5]]],[discrete,[[0.3,.5]]], [discrete,[[0.4,.5]]],[discrete,[[0.5,.5]]], [discrete,[[0.6,.5]]],[discrete,[[0.7,.5]]], [discrete,[[0,0]]],[discrete,[[0.1,0]]], [discrete,[[0.2,0]]],[discrete,[[0.3,0]]], [discrete,[[0.4,0]]],[discrete,[[0.5,0]]],[discrete,[[0.6,0]]],[discrete,[[0.7,0]]] ], [style,[points,5,1]], [xlabel,""],[ylabel,""], ['x,-0.2,1],['y,-0.2,0.7], [box,false],[axes,false], [legend,"1 ","2 ","3 ","4 ","5 ","6 ","7 ","8 ","9 ", "10 ","11 ","12 ","13 ","14 ","15 ","16 "])$ "-----------------------------------------"$ " 5. test number-(point type) association with [style, [points,5,1,1], [points,5,1,2],..] syntax."$ " this uses [point,nradius,ncolor,ntype ] syntax. Again should be 13 distinct point types ideally."$ plot2d([ [discrete,[[0,.5]]],[discrete,[[0.1,.5]]],[discrete,[[0.2,.5]]],[discrete,[[0.3,.5]]], [discrete,[[0.4,.5]]],[discrete,[[0.5,.5]]], [discrete,[[0.6,.5]]],[discrete,[[0.7,.5]]], [discrete,[[0,0]]],[discrete,[[0.1,0]]], [discrete,[[0.2,0]]],[discrete,[[0.3,0]]], [discrete,[[0.4,0]]],[discrete,[[0.5,0]]], [discrete,[[0.6,0]]],[discrete,[[0.7,0]]] ], [style, [points,5,1,1], [points,5,1,2], [points,5,1,3], [points,5,1,4], [points,5,1,5], [points,5,1,6], [points,5,1,7], [points,5,1,8], [points,5,1,9], [points,5,1,10], [points,5,1,11], [points,5,1,12], [points,5,1,13], [points,5,1,14], [points,5,1,15], [points,5,1,16] ], [xlabel,""],[ylabel,""],['x,-0.2,1],['y,-0.2,0.7], [box,false],[axes,false], [legend,"1 ","2 ","3 ","4 ","5 ","6 ","7 ","8 ","9 ", "10 ","11 ","12 ","13 ","14 ","15 ","16 "])$ "-----------------------------------------"$ " 6. test alternative point type syntax using [style,[points,5,1]], [point_type, t1,t2, ...],"$ " in which t1, t2,...are spelled out descriptions of line types,"$ " such as bullet, box, etc. This method should achieve all 13 distinct point types."$ plot2d([ [discrete,[[0,.5]]],[discrete,[[0.1,.5]]],[discrete,[[0.2,.5]]],[discrete,[[0.3,.5]]], [discrete,[[0.4,.5]]],[discrete,[[0.5,.5]]], [discrete,[[0.6,.5]]],[discrete,[[0.7,.5]]], [discrete,[[0,0]]],[discrete,[[0.1,0]]], [discrete,[[0.2,0]]],[discrete,[[0.3,0]]], [discrete,[[0.4,0]]],[discrete,[[0.5,0]]],[discrete,[[0.6,0]]],[discrete,[[0.7,0]]] ], [style,[points,5,1]], [point_type, bullet,circle,plus,times,asterisk,box,square,triangle,delta, wedge,nabla,diamond,lozenge,bullet,circle,plus], [xlabel," "],[ylabel," "], ['x,-0.2,1],['y,-0.2,0.7], [box,false],[axes,false], [legend,"bullet ","circle ","plus ","times ","asterisk ","box ", "square ","triangle ","delta ","wedge ","nabla ", "diamond ","lozenge ","bullet ","circle ","plus "])$ "-----------------------------------------"$ " 7. test indep. range control with plot2d ( sin(u),['u,0,%pi/2],['x, -0.2, 1.8] ) "$ " in which the parameter u controls the range of the drawing, and the parameter x"$ " describes the canvas width. Some versions of Maxima will object to this syntax."$ /* If you want to stick with a version of Maxima in which this syntax results in an error, you can achieve the desired plot by using the draw package. (You only need to load the draw package once per session.) load (draw)$ draw2d ( xrange = [-0.2, 1.8],yaxis = true, color = blue, explicit (sin(u),u,0,%pi/2), xlabel = "u", ylabel = "sin(u)")$ */ plot2d ( sin(u),['u,0,%pi/2],['x, -0.2, 1.8] )$ "-----------------------------------------"$ " 8. another more complicated range control and canvas width example. "$ /* A draw package version corresponding to the following plot2d plot is: draw2d ( xrange = [-0.2, 2.5], yrange = [-1, 4], xaxis=true,yaxis=true, line_width = 5, color= black,key="u^2", explicit (u^2,u,0,2), color= red,key = "u^3", explicit (u^3,u,0,2), xlabel = "u")$ */ plot2d( [u^2,u^3],['u,0,2], ['x, -.2, 2.5], [style, [lines,5,5],[lines,5,2]], ['y,-1,4] )$ "-----------------------------------------"$ " 9. test independent control of range, canvas width, grid, key position, title."$ " In some versions of Maxima, the separate range control will result in an"$ " error, and in some versions, the 'set grid' argument in the"$ " gnuplot_preamble string will not return a plot with a grid."$ " One can still toggle a grid on and off with the button on the"$ " gnuplot window."$ /* A draw2d version of the following plot2d plot is: draw2d ( xrange=[-8,8],yrange = [-3.5,2],grid = true, xaxis = true, xaxis_width = 2, xaxis_type = dots, xaxis_color = brown, yaxis = true, yaxis_width = 2, yaxis_type = dots, yaxis_color = brown, line_width = 4, color = blue, key = "u*sin(u)", explicit(u*sin(u),u,-4,4), color = red, key = "cos(u)", explicit(cos(u),u,-4,4), user_preamble = "set key bottom center")$ */ plot2d([ u*sin(u),cos(u)],['u,-4,4] ,['x,-8,8], [style,[lines,5]], [gnuplot_preamble,"set grid; set key bottom center; set title 'Two Functions';"])$ " 10. Simple parametric plot using t as the parametric parameter. "$ /* A draw2d version of the following plot2d plot is (may not be round) draw2d (xrange = [-sqrt(2),sqrt(2)], xaxis = true, yaxis = true, color = blue, parametric (cos(t),sin(t),t,0,2*%pi), xlabel = "cos(t)", ylabel = "sin(t)")$ To get a round circle with draw2d, add the option: proportional_axes = xy draw2d (xrange = [-sqrt(2),sqrt(2)], xaxis = true, yaxis = true, color = blue, parametric (cos(t),sin(t),t,0,2*%pi), xlabel = "cos(t)", ylabel = "sin(t)", proportional_axes = xy)$ */ plot2d ([parametric,cos(t),sin(t),[t,0,2*%pi]],[x,-sqrt(2),sqrt(2)])$ "-----------------------------------------"$ " 11. test parametric plot using t as the parametric plot parameter, and with discrete points added."$ " this should work with any version of Maxima."$ /* a draw2d version of the following plot2d plot is draw2d ( xrange=[-3,4],yrange = [-1,40], xaxis = true, xaxis_width = 2, xaxis_type = solid, xaxis_color = red, yaxis = true, yaxis_width = 2, yaxis_type = solid, yaxis_color = brown, line_width = 4, color = black, key = " ", parametric (2*cos(t),t^2,t,0,2*%pi), point_type = filled_circle, point_size = 2, color = blue, key = "t = 0", points ([[2,0]]), color = red,key = "t = pi/2", points ([[0,(%pi/2)^2]]), color = green,key = "t = pi", points ([[-2,%pi^2]]), color = magenta,key = "t = 3*pi/2", points ([[0,(3*%pi/2)^2]]))$ */ obj_list : [ [parametric, 2*cos(t),t^2,['t,0,2*%pi]], [discrete,[[2,0]]],[discrete,[[0,(%pi/2)^2]]], [discrete,[[-2,%pi^2]]],[discrete,[[0,(3*%pi/2)^2]]] ]$ style_list : [style, [lines,4,5],[points,5,1,1],[points,5,2,1], [points,5,3,1],[points,5,4,1]]$ legend_list : [legend, " ","t = 0","t = pi/2","t = pi", " t = 3*pi/2"]$ plot2d( obj_list, ['x,-3,4], ['y,-1,40],style_list, [xlabel,"X = 2 cos( t ), Y = t ^2 "], [ylabel, " "] ,legend_list )$ "-----------------------------------------"$ " 12. Can we use th as the parameter in a parametric plot?"$ " In some versions of Maxima (such as 5.40.0 and 5.41.0),"$ " this will result in an error."$ /* A draw2d version of the following plot2d plot is: draw2d (xrange = [-sqrt(2),sqrt(2)], xaxis = true, yaxis = true, color = blue, parametric (cos(th),sin(th),th,0,2*%pi), xlabel = "cos(th)", ylabel = "sin(th)")$ */ plot2d ([parametric,cos(th),sin(th),[th,0,2*%pi]],[x,-sqrt(2),sqrt(2)])$