0
$\begingroup$

I want to represent a 4-dimension data ({{x1},{x2}, {x3}, {y}}) using 2D scatter plot with color and point size variation. I make some initial trying based on 2D scatter plot with color bar legend

Below is the code, I got the point size variation but lost the color variation of the data points. Could somebody help me? Thanks a lot. P.S. Do not need to worry about the position of the color bar.

x1 = RandomReal[10, 100];
x2 = RandomReal[10, 100]; 
x3 = RandomReal[10, 100] + 2;
y = RandomReal[10, 100];

plotLegend[{min_, max_}, n_, col_] := 
 Graphics[{{col[(# - 1)/(n - 1)], 
      Rectangle[{0, # - 1}, {1, #}]}, {Black, 
      Text[NumberForm[
        Rescale[#, {1, n}, {min, max}], {3, 1}], {3, # - .5}, {1, 
        0}]}} & /@ Range@n, Frame -> True, Background -> White, 
  FrameTicks -> None, FrameLabel -> {"", "", "x3", ""}, 
  PlotRangePadding -> .5]

colorf = Blend[{Orange, Blue}, #] &; 
pP = Graphics[{{Table[{PointSize[(x2[[i]] + 5)/500], 
      Point[{x1[[i]], y[[i]]}]}, {i, 1, Length@x1}], 
    VertexColors -> colorf /@ Rescale@(x3)}, 
   Inset[plotLegend[{Min@#, Max@#} &@x3, 6, colorf], 
    Scaled[{0.7, 0.30}], ImageScaled[{0.1, 1/2}], 
    Scaled[{1/3, 0.6}]]}, PlotRange -> {All, {0, 12}}, Axes -> None, 
  Frame -> True, GridLines -> Automatic, AspectRatio -> 0.8, 
  FrameLabel -> {"x1", "y"}]
$\endgroup$
2
$\begingroup$

Just put the colours in the Graphics[Table[]]

Graphics[{{Table[{PointSize[(x2[[i]] + 5)/
       500], (colorf /@ Rescale@(x3))[[i]], 
     Point[{x1[[i]], y[[i]]}]}, {i, 1, Length@x1}]}, 
  Inset[plotLegend[{Min@#, Max@#} &@x3, 6, colorf], 
   Scaled[{0.7, 0.30}], ImageScaled[{0.1, 1/2}], Scaled[{1/3, 0.6}]]},
  PlotRange -> {All, {0, 12}}, Axes -> None, Frame -> True, 
 GridLines -> Automatic, AspectRatio -> 0.8, 
 FrameLabel -> {"x1", "y"}]

enter image description here

$\endgroup$
  • $\begingroup$ Thanks a lot, that is exactly what I want! $\endgroup$ – yanfyon Sep 2 '16 at 3:07

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.