Group Abstract Group Abstract

Message Boards Message Boards

0
|
5K Views
|
4 Replies
|
2 Total Likes
View groups...
Share
Share this post:

VertexColors not working with ListPlot3D

My problem is quite simple: I have a 2D array of "height" values (floating point) for a 3D array of data (x and y values are implied), and an equally sized 2D array of color data which may not be assigned using a simple color function because color is not dependent on the height value and must be pre-computed. To get around using the color function, I thought to assign the vertex colors directly.

My code is simply:

data = Import[*file*]
colors = ToExpression /@ Import[*file*]
ListPlot3D[data, VertexColors->colors]

However, I get a runtime error:

VertexColors::errmatrixcol: {"magenta", "magenta", ...} must be a color-valued matrix of X by Y.

It is odd, because the online documentation does not use the terminology "color-valued" anywhere. I've tried using colors (converted from imported string as shown), RGB values, 6-digit hex representation, raw color strings, and I always receive the same error.

I've also tried the methods shown here, which do not require converting the string to a color using "ToExpression". The examples provided work well as provided, but I cannot get them to work with my data. I should mention my array is 15x12,000 but the example does not work for even simple arrays, such as 5x5. I even thought the problem had to do with my older version (10.2), but the problem persists in 10.3.1. Does anyone have a solution?

I've also thought to try to plot this directly using Graphics3D, however the data plots just fine as:

ListPlot3D[data]

enter image description here

Also worth noting, the error disappears if:

color = ToExpression /@ Import[*file*] // TableForm;
ListPlot3D[data, VertexColors->colors]

However, the plot is the same default color, and therefore the VertexColors assignment is not working for some reason. If anyone may have an idea as to why this is occurring, I would be most grateful.

POSTED BY: Gary Lawson
4 Replies

Sander,

I followed your method exactly and the colors were properly rendered! Thank you very much for the help! And tally was a great addition, I was not aware of this function before and proves helpful as well.

POSTED BY: Gary Lawson

I'm not sure where your example goes wrong here is the correct way:

SetDirectory[NotebookDirectory[]];
data=Import["data.csv"];
colors=Import["color.csv"];
colors=Map[ToExpression,colors,{2}];
colors//Flatten//Tally
Dimensions/@{colors,data}

Note that I Map ToExpression over level 2, rather than level 1 as you did.

ListPlot3D[data, VertexColors -> {colors}]

VertexColors needs an extra {} for some reason I'm not sure of, probably if you have multiple plots, to distinguish each vertexcolors for each plot...

POSTED BY: Sander Huisman

Sander, thanks for your reply:

Yes I am able to run examples, such as the one I hyperlinked. Again, I cannot make the examples work with my data.

I'm using a 2D list of data, as I described terribly.

For the error, I lazily retyped the message and did not capitalize the color in the error; in the data files, the colors are capitalized (see colors.csv). Also, with the ToExpression command, I'm able to verify that the colors are imported correctly.

With a random array of colors, I receive the same error.

I've attached two files, examples of what I'm using; you can re-create the plot I previously screen captured with data.csv.

Attachments:
POSTED BY: Gary Lawson
POSTED BY: Sander Huisman
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard