<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//en">

<!–Converted with LaTeX2HTML 2022 (Released January 1, 2022) –> <HTML lang="en"> <HEAD> <TITLE>Contents of 3-D Plotting</TITLE>

<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=utf-8"> <META NAME="viewport" CONTENT="width=device-width, initial-scale=1.0"> <META NAME="Generator" CONTENT="LaTeX2HTML v2022">

<LINK REL="STYLESHEET" HREF="rlabp_tex.css">

<LINK REL="previous" HREF="node49_mn.html"> <LINK REL="up" HREF="node47_mn.html"> <LINK REL="next" HREF="node51_mn.html"> </HEAD>

<BODY bgcolor="#ffffff" text="#000000" link="#9944EE" vlink="#0000ff" alink="#00ff00">

<H2><A ID="SECTION000123000000000000000"> 3-D Plotting</A> </H2>

<P> Plotting 3-dimensional data is quite straightforward, and very similar to the steps used for plotting 2-dimensional data. We will begin with an example:

<P> <PRE> &gt; // Create the data &gt; X = -2:2:.2; &gt; Y = X; &gt; Z = []; &gt; for (i in 1:X.n) &gt; for (j in 1:Y.n) &gt; Z[i;j] = X[i] * exp (-X[i]^2 - Y[j]^2); &gt; &gt; &gt; // Make the plot &gt; pstart(„"xwin"); &gt; plwid(4); &gt; ptitle("Sample 3-D Plot"); &gt; xlabel("X-Axis"); &gt; ylabel("Y-Axis"); &gt; zlabel("Z-Axis"); &gt; plmesh( &lt;&lt; x = X; y = Y; z = Z &gt;&gt; ); &gt; plprint("3d.ps"); </PRE>

<P>

<DIV class="CENTER"><A ID="p3d"></A><A ID="509"></A> <TABLE> <CAPTION class="BOTTOM"><STRONG>Figure:</STRONG> Example 3D Plot</CAPTION> <TR><TD><IMG STYLE="height: 286.76ex; " SRC="img9.png" ALT="

\begin{figure}\begin{picture}(300,350)(0,120) % (x-size, y-size) (x-shift, y-shi...
......angle=90 hscale=80 vscale=80 voffset=40 hoffset=530
\end{picture}\end{figure}
"></TD></TR> </TABLE> </DIV>

<P> The output from the plprint command appears in Figure&nbsp;<A HREF="node50_ct.html#p3d"><IMG ALT="[*]" SRC="crossref.png"></A>. Now we must take a minute and explain the data passed as input to <code>plot3</code>. Three dimensional plots have two independent variables (vectors), <code>x</code>, and <code>y</code>. The dependent variable <code>z</code> (a matrix) is a function of both <code>x</code> and <code>y</code> and has row dimension the length of <code>x</code> and column dimension the length <code>y</code>. This storage scheme for three-dimensional data is economical in terms of memory, and allows the user some extra flexibility. Thus, the argument to <code>plot3</code> is a list with three elements: <code>x</code>, <code>y</code>, and <code>z</code>. <code>plot3</code> can accept up to three distinct lists for plotting.

<P> The same plot-functions: <code>ptitle</code>, <code>xlabel</code>, and <code>ylabel</code> can be used with 3-dimensional plots. Additionally, <code>zlabel</code> can be used to add labels to the <code>z</code> axis.

<P> The next example (Figure&nbsp;<A HREF="node50_ct.html#p6"><IMG ALT="[*]" SRC="crossref.png"></A>) demonstrates more plotting capabilities - including: changing fonts and pen widths, multiple plots per page and annotating a plot. Note that the calls to <code>plptex</code> are made <EM>after</EM> the <code>plot</code> calls. since <code>plptex</code> uses the plot coordinates to place text on the graph, the plot must be created first.

<P> <PRE> // // Demonstrate the effect of adding terms to a Fourier expansion //

// We want to approximate a square wave... // The Fourier Series for a square wave is a // sum of odd harmonics - we will demonstrate. // Start up a plot window...

pstart(2,2, "xwin");

// Compute the 1st term in the Fourier series and plot.

t = (0:10:.1)'; y = sin (t);

ptitle ("Fundamental Frequency"); plwid(10); plfont(1); plot ( [t,y] ); plptex ("Pen width = 10", 4, 0.4); plptex ("Font = 1 (Normal)", 4, 0.1); pause ();

// Now add the third harmonic to the fundamental, and plot.

y = sin (t) + sin (3*t)/3;

ptitle ("1st and 3rd Harmonics"); plwid(7); plfont(4); plot ( [t,y] ); plptex ("Pen width = 7", 4, 0.4); plptex ("Font = 4 (Script)", 4, 0.1); pause ();

// Now use the first, third, fifth, seventh, and ninth harmonics.

y = sin (t) + sin (3*t)/3 + sin (5*t)/5 + sin (7*t)/7 + sin (9*t)/9; ptitle ("1st, 3rd, 5th, 7th, 9th Harmonics"); plwid(4); plfont(3); plot ( [t,y] ); plptex ("Pen width = 3", 4, 0.4); plptex ("Font = 3 (Italic)", 4, 0.1); pause ();

// // Now create a matrix with rows that represent adding // more and more terms to the series. //

t = (0:3.14:.02); y = zeros(10,max(size(t))); x = zeros(size(t));

for (k in 1:19:2) x = x + sin(k*t)/k; y[(k+1)/2;] = x;

// // Now make a nice 3-D plot that shows the effect // of adding more and more terms to the series. //

plfont (2); plwid(1); ptitle ("Square Wave via Fourier Series"); ylabel ("No. Terms"); plaz (140); plot3 (&lt;&lt; x = t; y=1:10; z=y' &gt;&gt;); plptex ("Pen width = 1", -1, 4.5); plptex ("Font = 2 (Roman)", -1, 3.8); plprint ("p6.ps"); // Make hardcopy (Postscript default). </PRE>

<P>

<DIV class="CENTER"><A ID="p6"></A><A ID="510"></A> <TABLE> <CAPTION class="BOTTOM"><STRONG>Figure:</STRONG> Square Wave Plot Example</CAPTION> <TR><TD><IMG STYLE="height: 286.76ex; " SRC="img10.png" ALT="

\begin{figure}\begin{picture}(500,450)(0,50) % (x-size, y-size) (x-shift, y-shif...
......angle=90 hscale=70 vscale=80 voffset=40 hoffset=500
\end{picture}\end{figure}
"></TD></TR> </TABLE> </DIV>

<P>

<P>

<HR>

</BODY> </HTML>