0
$\begingroup$

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"]]]
$\endgroup$
  • $\begingroup$ "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? $\endgroup$ – J. M. is away Jan 6 '17 at 10:59
  • $\begingroup$ Now it is corrected. However problem not solved! $\endgroup$ – Abhijit Saha Jan 6 '17 at 11:03
  • $\begingroup$ Like this? $\endgroup$ – J. M. is away Jan 6 '17 at 11:10
  • $\begingroup$ Yes. Absolutely, Could you please post the code. Thanks $\endgroup$ – Abhijit Saha Jan 6 '17 at 11:16
1
$\begingroup$
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}}]]]

enter image description here

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}.
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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