How to make a multi coloured, 3d plot, from a list of points.

Hey guys, I am currently writing a dynamic programming program. This program is used to simulate and optimize turbine operations.

The program produces a grid of nodes. At each node (each node has an X and Y coordinate), one of 5 differential equations is evaluated. A flag indicating which differential equation was used, as well as the dZ from the DE is stored at each node.

I want the X,and Y values of the nodes coorespond to the X and Y values of the plot. I want the dZ to coorespond to the Z axis. I also want each individual point to be colour coded reflecting which DE was used to calculate the dZ.

I know how to simply plot a bunch of 3d points:

 

however I do not know how to change the colour at each point.
I also have the problem of getting the data from my program into maple. Right now i am writing to a .txt outfile, then copying and pasting the points into a plot function like I have shown above. Does anyone have some faster and more efficientways of getting my data into maple ?

Thanks in advance, -Paul

 

pointplot3d({[1,1,1],[2,2,2],[3,3,4]});

Robert Israel's picture

Points with colours

Suppose your text file consists of lines of the form

c, x, y, z

where c is 1 to 5 (for the colour code) and [x,y,z] is the point to plot, using commas as separators.

> M := ImportMatrix("c:/mypath/myfile.txt", source=csv);
   colours:= [red, green, blue, cyan, black];

The following will work in Standard, but not in Classic.

> plots[pointplot3d](M[1..-1,2..4],
      color=convert(map(t->colours[t], M[1..-1,1]),list));

Alternatively, you might separate out the points of each colour, plot them separately, and combine the plots with display.  This will work in both Standard and Classic.

>  with(plots):
   display([seq](pointplot3d(M[
   select(t -> (M[t,1]=j),[$1..LinearAlgebra[RowDimension](M)])
         , 2..4], 
       colour=colours[j]), j=1..5));

 

Colours for pointplot3d

Hi Paul,

I'll try your last q first. You can use the Data Import assistant (Tools>Assistants>Import Data) to import your data from, for instance, an Excel or some delimited file. Maple will import the data as rtable which can be used to construct arrays, matrices, or vectors.

From the help page for this command (?pointplot3d at the Maple prompt):

"The option color=s specifies the color of the points. The allowable values for s are given in the plot/color help page. A list of n colors, where n is the number of points, may also be provided. "

It is possible you could write a Maple procedure to output a list of colours matching the 3D points you've imported.  If you can set up your data so when it imports you have 3 columns for the 3D point values as well as a corresponding 4th column indicating what DE was used, your procedure could extract this info and return a list of colours in the same order as the points.

i.e. pointplot3d({list of points}, color={list of colours}).

- Stephanie

error and new question..

 

Hey guys, thanks for your osts.

Robert Israel, I tried the code that you gave me and got the following error:

Error, (in ImportMatrix) argument 'source = csv' invalid: rhs should be of type {identical(Matlab), identical(MatrixMarket), identical(delimited)}

I have also decided that instead of the Z dimention, I want to just capture that z information in the form of a direction vector at each 2d point sort of like a slope feild, any ideas on how I might do this? (i still want the vectors to be coloured based on the DE i used).

 

Robert Israel's picture

source=csv

You must be using Maple 9.5 or earlier: source = csv works in more recent versions.
Well, it should still work if you tell ImportMatrix that the delimiter is ",".  Thus:

> M := ImportMatrix("c:/mypath/myfile.txt", delimiter=",");

If you want the z entry to be a slope, you could do something like this:
 

> with(plots): 
   n := LinearAlgebra[RowDimension](M);
   r := (max-min)(seq(M[i,2],i=1..n))/10; 
   display([seq](arrow([M[i,2],M[i,3]], 
         evalf([1, M[i,4]]*r/sqrt(1+M[i,4]^2)), 
       colour=colours[M[i,1]], shape=arrow), 
      i=1..n));

Here r is the length for each arrow; I tried to make a reasonable choice, based on the range of x values in the plot, but you can adjust this according to taste.

sorry to be needy

Sorry to be needy, i just dont really understand your code well enough to make changes to it. I have set values for max and min in your code and typed it into maple:

> M := ImportMatrix("D:/Programs/TidalDP/ohmax.txt", delimiter=",");

                         [ 2000 x 4 Matrix      ]
                    M := [ Data Type: anything  ]
                         [ Storage: rectangular ]
                         [ Order: Fortran_order ]

> with(plots):
>    n := LinearAlgebra[RowDimension](M);
>    r := (1)(seq(M[i,2],i=1..n))/10;
>    display([seq](arrow([M[i,2],M[i,3]],
>          evalf([1, M[i,4]]*r/sqrt(1+M[i,4]^2)),
>        color=colors[M[i,1]], shape=arrow),
>       i=1..n));

                              n := 2000

                              r := 1/10

Error, (in plot/color) invalid color specification

>
>
 

I should mention im using

I should mention im using maple 7, maybe i should upgrade lol

Define colours first

Did you remember to define the list of colors? In Robert's example, he includes this command right after the ImportMatrix call: 
colours:= [red, green, blue, cyan, black];

Paulina Chin
Maplesoft

Yes! it finally works. I

Yes! it finally works. I will post some pictures for you guys later of what I am doing once I get the equations working :). Thanks alot guys

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
}