Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

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?

share|improve this question
add comment

1 Answer

up vote 4 down vote accepted

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?

share|improve this answer
    
I found it here: mathematica.stackexchange.com/questions/20023/…, in the second answer. –  flaviotruzzi Apr 19 '13 at 13:44
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.