Message Boards Message Boards

0
|
4874 Views
|
5 Replies
|
0 Total Likes
View groups...
Share
Share this post:

Represent three dimensions of data on a 2D ListPlot?

Posted 7 years ago

Is it possible to make a List Plot in which each point is colored based on the count of that point's {x,y} occurrence in the data set? Specifically, I have data of the form data={{x1,y1}->c1, ... ,{xn,yn}->cn} where cn is the nth count for the occurrence of {xn,yn} in the data set. I can almost get what I want in two ways:

Method 1:

ListPlot[{#1} & @@@ data,PlotMarkers -> cf /@ #2 & @@@ data]

where cf is my ColorDataFunction[], and I have neglected my plotting options for clarity.

Method 2:

ListPlot[{#1} & @@@ data,PlotStyle -> cf /@ #2 & @@@ data]

again where cf is my ColorDataFunction[], and I have neglected my plotting options for clarity.

For method 1, the rendered markers are large squares, and for method 2, the markers are automatically sized. In both cases, I loose control of marker size and shape customization.

POSTED BY: Jacob Lapenna
5 Replies
POSTED BY: Moderation Team

I would try with graphics primitives:

data = {{0, 0} -> 2, {1, 1} -> 1, {-2, -3} -> 1};
nmax = Max[data[[All, -1]]];
Graphics[{PointSize[Large], 
  data /. ({x_, y_} -> n_Integer) :> {Hue[n/nmax], Point[{x, y}]}}]
POSTED BY: Gianluca Gorni

Apart from Gianlucas short and elegant solution I think it might be a good idea to reorder your data first. This way you can make sure that "interesting" points are not overlapped by "uninteresting" ones. Here a minimal example (using List of List instead of List of Rules):

data = RandomInteger[100, {100^2, 2}];
tdata0 = Tally[data];
tdata1 = GatherBy[SortBy[tdata0, Last], Last];
tdata2 = Transpose /@ tdata1;
tdata3 = First[Transpose@tdata2];

Here in this case we have 7 different occurences:

Length[tdata3]
(* Out:    7 *)

Now in the most simple case we can do

ListPlot[tdata3, AspectRatio -> Automatic, 
 PlotStyle -> {Directive[GrayLevel[0], PointSize[1 s]], 
    Directive[GrayLevel[.5], PointSize[2 s]], 
    Directive[RGBColor[0, 0, 1], PointSize[3 s]], 
    Directive[RGBColor[1, 0, 0], PointSize[4 s]], 
    Directive[RGBColor[1, 1, 0], PointSize[5 s]], 
    Directive[RGBColor[0, 0, 1], PointSize[6 s]], 
    Directive[RGBColor[0, 1, 0], PointSize[7 s]]} /. s -> .005]

which already results in:

enter image description here

Well, of course if you do not have that many data, then Gianlucas solution is surely preferable!

POSTED BY: Henrik Schachner

You may consider using BubbleChart, if you haven't already. It has a similar purpose.

POSTED BY: Gianluca Gorni
Attachments:
POSTED BY: Jacob Lapenna
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract