# PlotLegends in 4D plot

I have a data set consisting of 4 points. Each point has 4 columns. I want to plot that data set with 4D color function where 4th column of each dataset will be plotted by the color function. The range of the 4th column is {2, 9}. However the PlotLegends bar is showing values ranging {0, 1}.

 rs13pts1 = {{1, .2, .6, 6}, {1.2, .4, .8, 7}, {1.4, .6, 1, 8}, {1.6, .8, 1.2, 9}};

Block[{i = 1},
ListPointPlot3D[rs13pts1[[All, ;; 3]], PlotRange -> All,
ColorFunction ->
Function[{x, y, z},
ColorData["RedGreenSplit"][rs13pts1[[i++, 4]]]],
PlotLegends -> BarLegend["RedGreenSplit"]]]

• "The range of 4th column is 2-6" - but the fourth coordinates of your points are outside that specified range; what do you actually want? Jan 6, 2017 at 10:59
• Now it is corrected. However problem not solved! Jan 6, 2017 at 11:03
• Like this? Jan 6, 2017 at 11:10
• Yes. Absolutely, Could you please post the code. Thanks Jan 6, 2017 at 11:16

rs13pts1 = {{1, .2, .6, 6}, {1.2, .4, .8, 7}, {1.4, .6, 1, 8}, {1.6, .8, 1.2, 9}};


I'd do

Block[{i = 1},
ListPointPlot3D[rs13pts1[[All, ;; 3]], PlotRange -> All,
PlotStyle -> PointSize[Large],
ColorFunction -> (ColorData["RedGreenSplit"][
Rescale[rs13pts1[[i++, 4]], {2, 9}, {0, 1}]] &),
PlotLegends -> BarLegend[{"RedGreenSplit", {2, 9}}]]]


where I

1. added PlotStyle -> PointSize[Large] just for the colors of the points to be more visible in this example;
2. altered PlotLegends by adding the interval {2, 9} to the BarLegend;
3. Rescaled the ColorFunction from the interval {0, 1} to {2, 9}.