5
$\begingroup$

I have an array of the following form {{a_n,b_n,c_n}} where n is quite large. I wish to plot a_n against b_n using Listplot with c_n specifying a ColorFunction perhaps Hue[] how would I go about this? Thank you

$\endgroup$
5
$\begingroup$

You could do that using Point and VertexColors:

data = {{1, 2, 0}, {2, 1, 0.5}, {3, 1.3, 0.6}, {4, 1.1, 0.8}};
Graphics[
 Point[data[[All, ;; 2]],VertexColors -> (Hue /@ data[[All, 3]])],
 Frame -> True, 
 ImageSize -> 400
]

enter image description here

This should be very good in terms of memory as you only have one Point object.

| improve this answer | |
$\endgroup$
4
$\begingroup$
data = RandomReal[{0, 10}, {100, 3}];

rng = MinMax@data[[All, 3]];

Legended[
 Graphics[
  {AbsolutePointSize[5],
   {ColorData["Rainbow"][Rescale[#[[3]], rng]],
      Tooltip[Point[#[[1 ;; 2]]], #[[3]]]} & /@
    data},
  Frame -> True,
  ImageSize -> 400,
  FrameLabel -> (Style[#, 14] & /@ {"a", "b"})],
 BarLegend[{"Rainbow", rng}]]

enter image description here

| improve this answer | |
$\endgroup$
1
$\begingroup$
SeedRandom[1]
data = Round[RandomReal[5, {20, 3}], .01];

You can use your 3D data as input to BubbleChart with the option ColorFunction -> (Hue[#3] &):

BubbleChart[data, ColorFunction -> (Hue[#3] &), 
 BubbleSizes -> {.03, .03}, 
 ChartLegends -> SwatchLegend[Hue /@ Rescale[Union[data[[All, -1]]]], 
   Union[data[[All, -1]]], LegendMarkers -> "Bubble"]]

enter image description here

Alternatively, you can wrap each point with List and ListPlot with the option PlotStyle:

ListPlot[List /@ data[[All, {1, 2}]], 
 PlotStyle -> (Hue /@ Rescale[data[[All, -1]]]), 
 BaseStyle -> PointSize[.03], ImageSize -> Medium, AspectRatio -> 1, 
 Frame -> True, 
 PlotLegends -> SwatchLegend[Union[styles], Union@data[[All, -1]], 
   LegendMarkers -> "Bubble"]]

enter image description here

| improve this answer | |
$\endgroup$
  • $\begingroup$ In terms of memory both are not very ideal: For a 100 points the bubblechart is 272664 bytes, the listplot 1086800, and my solution with vertexcolor just 9344 bytes. (i removed the legend from both). $\endgroup$ – SHuisman Mar 4 at 17:09
  • 1
    $\begingroup$ @SHuisman, very good point. Got distracted with ListPlot and ColorFunction and missed the large n bit. $\endgroup$ – kglr Mar 4 at 17:12
  • $\begingroup$ 'quite large' could mean 100 or 10^8 so I'm not sure about the importance… But both ListPlot and BubbleChart have a lot of overhead. $\endgroup$ – SHuisman Mar 4 at 17:20

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.