0

I have a list of data with dimensions $(2000,4)$.

I plotted it using ListPointPlot3D, setting the fourth dimension as the color. As follows:

ListPointPlot3D[List /@ data[[All, {1, 2, 3}]], 
  PlotStyle -> ({PointSize[Large], 
       Blend[{{0, Darker[Green]}, {5, Yellow}, {10, Red}}, #1]} & /@ 
     Flatten[data[[All, {4}]]]), RotationAction -> "Clip"]

I want to show the colorbar, I tried the function ShowLegend, but it didn't work. Any ideas?

Sjoerd C. de Vries
  • 65,815
  • 14
  • 188
  • 323
flaviotruzzi
  • 111
  • 3

1 Answers1

4

Assuming you have version 9, which has new legending functions, this is how I would do it.

data = Flatten[
   Table[{x, y, Sin[ x y/50], Cos[x y/50]}, {x, 0, 
     10 π, π/10}, {y, 0, 10 π, π/10}], 1];

ListPointPlot3D[data[[All, {1, 2, 3}]], ColorFunction -> Function[{x, y, z}, ColorData["IslandColors"][z]], PlotLegends -> BarLegend[{ColorData["IslandColors"], {-1, 1}}]]

enter image description here

ShowLegend is a function from the old and much deviled PlotLegends package. If you intended to use that, you may have forgotten to include the package using Needs.

In earlier versions you would write something like:

Needs["PlotLegends`"]

ShowLegend[ ListPointPlot3D[data[[All, {1, 2, 3}]], ColorFunction -> Function[{x, y, z}, ColorData["IslandColors"][z]]], {ColorData["IslandColors"][ 1 - #1] &, 10, " 1", "-1", LegendPosition -> {1.1, -.4}}]

enter image description here

Much of what you wrote yourself doesn't seem to make sense. The List/@ part is unnesessary as you can see from how I handle the data matrix. PlotStyle doesn't take a pure function as argument. Where did you encounter a construction like that?

Sjoerd C. de Vries
  • 65,815
  • 14
  • 188
  • 323
  • I found it here: http://mathematica.stackexchange.com/questions/20023/plot-4d-data-with-color-as-4th-dimension, in the second answer. – flaviotruzzi Apr 19 '13 at 13:44