0
$\begingroup$

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?

$\endgroup$

1 Answer 1

4
$\begingroup$

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?

$\endgroup$
1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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