/* [wxMaxima batch file version 1] [ DO NOT EDIT BY HAND! ]*/
/* [ Created with wxMaxima version 24.02.1 ] */
/* [wxMaxima: title   start ]
Advanced visualization examples
   [wxMaxima: title   end   ] */


/* [wxMaxima: section start ]
Embedding plots
   [wxMaxima: section end   ] */


/* [wxMaxima: comment start ]
Embedding a plot into the worksheet is easy: Just prepend the plot()- or draw()-command with a "wx":
   [wxMaxima: comment end   ] */


/* [wxMaxima: input   start ] */
draw2d(
    grid=[5,5],
    explicit(
        sin(x),
        x,0,4*π
    )
)$
/* [wxMaxima: input   end   ] */


/* [wxMaxima: input   start ] */
wxdraw2d(
    grid=[5,5],
    explicit(
        sin(x),
        x,0,4*π
    )
)$
/* [wxMaxima: input   end   ] */


/* [wxMaxima: section start ]
Logarithmic axes
   [wxMaxima: section end   ] */


/* [wxMaxima: input   start ] */
wxdraw2d(
    logx=false,logy=true,
    grid=[5,10],
    key="3^x",color=green,line_type=1,
    explicit(3^x,x,1,10),
    key="10·3^x",line_type=2,
    explicit(10*3^x,x,1,10),
    key="5^x",color=red,line_type=1,
    explicit(5^x,x,1,10),
    key="10·5^x",line_type=2,
    explicit(10*5^x,x,1,10),
    key_pos='top_left
)$
/* [wxMaxima: input   end   ] */


/* [wxMaxima: section start ]
Changing the physical units being used
   [wxMaxima: section end   ] */


/* [wxMaxima: comment start ]
The following examples uses two approaches to changing the scale:
 * A subst that moves T from the Kelvin to the Celsius scale
 * Adding a second axis that uses a different set units
   [wxMaxima: comment end   ] */


/* [wxMaxima: input   start ] */
wxdraw2d(
    grid=[5,5],
    xrange_secondary=[0,100]+273.25,
    xtics_secondary=true,
    xlabel_secondary="T [K]",
    xlabel="T [°C]",ylabel="Heat dissipation [unitless]",
    xrange=[0,100],
    explicit(subst(T=Celsius+273.25,T^4/1e9),Celsius,0,100)
)$
/* [wxMaxima: input   end   ] */


/* [wxMaxima: section start ]
Improving the plot accuracy
   [wxMaxima: section end   ] */


/* [wxMaxima: comment start ]
Maxima's plot functions try to determine in which region it makes sense to invest much effort. If  that results into too coarse curves setting nticks high enough normally helps
   [wxMaxima: comment end   ] */


/* [wxMaxima: input   start ] */
wxdraw2d(
    key="nticks=(the default value)",color=red,
    parametric(sin(φ)*φ,cos(φ)*φ,φ,1,20*π),
    nticks=2000,key="nticks=2000",color=blue,
    parametric(sin(φ)*φ,cos(φ)*φ,φ,1,20*π)
)$
/* [wxMaxima: input   end   ] */


/* [wxMaxima: section start ]
Drawing discrete data
   [wxMaxima: section end   ] */


/* [wxMaxima: comment start ]
By default maxima draws discrete data as points, but one can tell it to connect them using lines.
The tick mark (') in front of the bottom_right tells maxima to use the name bottom_right even if the variable bottom_right happens to have been assigned a value to.
   [wxMaxima: comment end   ] */


/* [wxMaxima: input   start ] */
xcoord:makelist(t,t,0,30)$
ycoord:makelist(sin(1/10*2*π*t),t,xcoord)$
/* [wxMaxima: input   end   ] */


/* [wxMaxima: input   start ] */
wxdraw(
        gr2d(
        points_joined=true,point_type='none,color=black,
        yrange=[-1,1],
        points(xcoord,ycoord),
        xrange=[0,15]
    ),
    gr2d(
        color=red,key="sin(2/10·π·t)",
        explicit(sin(1/10*2*π*t),t,0,30),
        color=blue,key="sin(22/10·π·t)",
        explicit(sin(11/10*2*π*t),t,0,30),
        key="Samples",color=black,
        point_type=2,point_size=2,
        points(xcoord,ycoord),
        xrange=[0,15],
        key_pos='bottom_right
    )
)$
/* [wxMaxima: input   end   ] */


/* [wxMaxima: section start ]
Drawing physical objects
   [wxMaxima: section end   ] */


/* [wxMaxima: comment start ]
If the plot functions are told to use the same scale for all axis and not to plot the coordinate system they can be misused for drawing pictures of everyday objects:
   [wxMaxima: comment end   ] */


/* [wxMaxima: input   start ] */
wxdraw2d(
    /* Make the X and Y scale identical */
    proportional_axes=xy,
    /* Disable the coordinate system */
    axis_top=false,axis_left=false,axis_bottom=false,axis_right=false,
    yaxis=false,yaxis=false,
    xtics=false,ytics=false,
    /* make the curves use more points than maxima normally believes to be necessary*/
    nticks=500,
    color=black, line_width=2,
    parametric(
        sin(α)*(1+.1*sin(α*50)),
        cos(α)*(1+.1*sin(α*50)),
        α,
        .02*π,1.96*π
    ),
    subst(
        α=.02*π,
        parametric(
            sin(α)*(1+.1*sin(α*50)),
            cos(α)*(1+.1*sin(α*50))+y,
            y,0,.4
        )
    ),
    subst(
        α=1.96*π,
        parametric(
            sin(α)*(1+.1*sin(α*50)),
            cos(α)*(1+.1*sin(α*50))+y,
            y,0,.4
        )
    )    
);
/* [wxMaxima: input   end   ] */


/* [wxMaxima: section start ]
A weird filled areas example
   [wxMaxima: section end   ] */


/* [wxMaxima: input   start ] */
region_red:((x-.3)^2+y^2<1);
region_green:((x+.3)^2+y^2<1);
region_blue:(x^2+(y+.3*sqrt(3))^2<1);
wxdraw2d(
    /* Increase the accuracy */
    nticks=50,x_voxel=150,y_voxel=150,fill_density=1,
    /* Make the X and Y scale identical */
    proportional_axes='xy,
    /* The filled areas */
    fill_color='red,
    region(
        region_red and (not (region_green or region_blue)),
        x,-2,2,y,-2,2
    ),
    fill_color='green,
    region(
        (region_green and (not (region_red or region_blue))),
        x,-2,2,y,-2,2
    ),
    fill_color='blue,
    region(
        (region_blue and (not (region_red or region_green))),
        x,-2,2,y,-2,2
    ),
    fill_color='yellow,
    region(
        (not region_blue) and (region_red and region_green),
        x,-2,2,y,-2,2
    ),
    fill_color='magenta,
    region(
        (not region_green) and (region_red and region_blue),
        x,-2,2,y,-2,2
    ),
    fill_color='cyan,
    region(
        (not region_red) and (region_green and region_blue),
        x,-2,2,y,-2,2
    ),
    fill_color='white,
    region(
        region_blue and region_red and region_green,
        x,-2,2,y,-2,2
    ),
    /* The borders of said areas*/
    color='black,
    parametric(sin(φ),cos(φ)-.3*sqrt(3),φ,0,2*π),
    parametric(sin(φ)+.3,cos(φ),φ,0,2*π),
    parametric(sin(φ)-.3,cos(φ),φ,0,2*π)
);

/* [wxMaxima: input   end   ] */



/* Old versions of Maxima abort on loading files that end in a comment. */
"Created with wxMaxima 24.02.1"$
