kill(all)$

maxima :appendix:fvm: matrix plot for 3d coordinates (or 2D image,or impulses),version 1.0
peter.vlasschaert@gmail.com,01/11/2022

1e) given matrix
---------------------

a:2;

p1:m: apply(matrix, makelist(makelist(random(1.0),k,1,a),i,1,a));
p2:f(x, y) := float('m [round(x), round(y)])$
p3:wxplot3d (f(x,y), [x,1,a], [y,1,a], [grid,a,a], nolegend)$

see : fig 1, matrix plot "matrix = m"

rem : don't for get : "p2"→ 'm ( not m),otherwise a error result

ma:transpose(m);

first     row of matrix(=ma) : close to    you
second row of matrix(=ma) : fahr from you

b:2;

m1: apply(matrix, [[1.25,1.65],[1.7,2]]) ;

f(x, y) := float('m1 [round(x), round(y)])$
 wxplot3d (f(x,y), [x,1,b], [y,1,b], [grid,b,b], nolegend)$

2e) random plot (random matrix)
-----------------------------------------

c:4;

m: apply(matrix, makelist(makelist(random(1.0),k,1,c),i,1,c)) ;
f(x, y) := float('m [round(x), round(y)])$
 wxplot3d (f(x,y), [x,1,c], [y,1,c], [grid,c,c], nolegend)$

? What to do when matrix is "not" square matrix.
-------------------------------------------------------------

1e step : given matrix (3 by  4)
--------------------------------------

m2: apply(matrix, makelist(makelist(random(1.0),k,1,3),i,1,4));

→ better view with "m2a"

m2a:transpose(m2);

2e step : plot random matrix
------------------------------------

f(x, y) := float('m2 [round(x), round(y)])$
wxplot3d (f(x,y), [x,1,4], [y,1,3], [grid,4,3], nolegend)$

figure : 2

wxplot3d : see for option "help .maxima", here "nolegend"

? How to make function to do this only with : input matrix
-------------------------------------------------------------------------

→ function : input matrix , string : info "see: output below"

myplot3mat(mm,figg):=block([rr,cc],
vv: transpose(mm), /*transpose of the matrix = mm */  
rr:length(mm),/* row       , x-direction */
cc:length(vv), /* column , y-direction */
f(xii, yii) := float('mm [round(xii), round(yii)]),
wxplot3d (f(xii,yii), [xii,1,rr], [yii,1,cc], [grid,rr,cc], nolegend),
print(figg),/* info : figure ,"string"*/
return(vv)
)$

→ output : myplot3mat

myplot3mat(m2,"figure 3:matrix plot:m2");

→ color matrixplot (with draw package)

wxdraw2d(image(transpose(m2),1,1,4-1,3-1),dimensions=[100,100]);

my2plot3mat(mm,figg1,figg2):=block([rr,cc],
vv: transpose(mm), /*transpose of the matrix = mm */  
rr:length(mm),/* row       , x-direction */
cc:length(vv), /* column , y-direction */
f(xii, yii) := float('mm [round(xii), round(yii)]),
wxplot3d (f(xii,yii), [xii,1,rr], [yii,1,cc], [grid,rr,cc], nolegend),
print(figg1),/* info : figure ,"string"*/
wxdraw2d(image(transpose(m2),1,1,rr-1,cc-1),
                  dimensions=[100,100]),
print(figg2),/* info : figure ,"string"*/   
    return(vv)
)$

figg1:"figure 3:matrix plot:m2";
figg2:"figure 4:color matrix plot '2D':m2";

my2plot3mat(m2,figg1,figg2);

other ways to display data 3d
------------------------------------

wxdraw3d(
         color = blue,
         grid = true,
         elevation_grid(transpose(m2),1,1,4-1,3-1),
         xlabel = "x",
         ylabel = "y",
         surface_hide = true);

   enhanced3d=true

coordinates of 3d points , z =thrid coordinate (values of m2)
--------------------------------------------------------------------------
mesh( 4 by 3)

x1:makelist(makelist([i1,i2,m2[i1,i2]],i1,1,4),i2,1 ,3);

→ first row

x1[3];

→ second row

x1[2];

→ third row

x1[1];

→ vertical line

wxdraw3d(
       /* the points */
       color = red,
       point_size =0.5,
       point_type = 7,
             grid=true,
       user_preamble="set border 4095",
       /* the lines */
       points_joined=true,
       points([[1,1,0],[1,1,m2[1,1]]])
       )$

x2:flatten(x1);

→ list of points in 3D

x3:makelist([x2[3*i+1],x2[3*i+2],x2[3*i+3]],i,0,12-1);

x3a:makelist([x2[3*i+1],x2[3*i+2],0],i,0,12-1);

wxdraw3d(
       /* the points */
       color = red,
       point_size =1,
       point_type = 7,
       xyplane       = 0,
             grid=true,
       user_preamble="set border 4095",     
       points(x3),/* z values : "values matrix"*/
       color =  green,
       points(x3a) /* z values :      0                */
       )$

x4:makelist([[x2[3*i+1],x2[3*i+2],0],[x2[3*i+1],x2[3*i+2],x2[3*i+3]]],i,0,12-1);

→ number of lines " given coordinates "

length(x4);

→ begin : point to end : point ( = vertical line coordinates)

x4[1]; /* first line in the list :coordinates*/

convert : matrix → list
=================

args(m2);

m2;

listp(args(m2));

reverse(x2);

wxdraw3d(
  points_joined = impulses,
  line_width    = 2,
  color         = "red",
  xyplane       = 0,/* impulses xyplane to matrix values ,with impulses*/
   points(makelist([x2[3*i+1],x2[3*i+2],x2[3*i+3]],i,0,11) ))$

optimized : version 
==============

my3plot3mat(mm,figg1,figg2,figg3):=block(
[rr,cc,ww,x22,xii,yii, i1,i2,ix],   
vv: transpose(mm), /*transpose of the matrix = mm */  
rr:length(mm),/* row       , x-direction */
cc:length(vv), /* column , y-direction */
f(xii, yii) := float('mm [round(xii), round(yii)]),
/*-------------------------------------------------------------------------*/    
wxplot3d (f(xii,yii), [xii,1,rr], [yii,1,cc], [grid,rr,cc], nolegend),
                print(figg1),/* info : figure ,"string"*/
                print("                           "),
wxdraw2d(image(transpose(m2),1,1,rr-1,cc-1),
                  dimensions=[100,100]),
                  print(figg2),/* info : figure ,"string"*/
                  print("                           "),    
ww:makelist(makelist([i1,i2,m2[i1,i2]],i1,1,rr),i2,1 ,cc),
x22:flatten(ww),    
wxdraw3d(
                 grid = true,
                  /* points : z-values */
                  point_size =1,
                  point_type = 7,
                  color = green,
                  points(makelist([x22[3*ix+1],x22[3*ix+2],x22[3*ix+3]],ix,0,11)),
                  /* vertical lines        */
                  points_joined = impulses,/*vertical lines from : the ref */
                  line_width    = 2,
                   color         = "red",
                   xyplane       = 0,                /* = ref */                  
                   points(makelist([x22[3*ix+1],x22[3*ix+2],x22[3*ix+3]],ix,0,11) )
                   ),               
                  print(figg3),/* info : figure ,"string"*/  
   print("                           "),
   print("matrix output : "),
   print("----------- "),
   return(vv)
)$

rem :rr "= local variable from the function above ."

rr;

→ title : matrix plot for the figure

figg3:"figure 5:matrix impulses plot:m2";

→ output :my3plot3mat

my3plot3mat(m2,figg1,figg2,figg3);

-------------------------------------------------------------------------------------------------------