8
$\begingroup$

I am plotting data using ListPlot, but many of my data points are exactly overlapping and so the density of the data is not shown clearly.

I wonder if there is a way to solve this, either by 'jittering' the points or by adjusting the size of the points to reflect the density of points at a particular coordinate. Any other ideas would be very welcome.

$\endgroup$
1

3 Answers 3

8
$\begingroup$

Considering you have duplicate points, you can use the number of times the data appears as your point size.

data = RandomReal[{0, 10}, {30, 2}];
data = Join[RandomChoice[data, 12], data]; (*duplicate data*)
data1 = Tally[data]; (*count number of appearance*)
Graphics[Disk[#[[1]], #[[2]] 0.1] & /@ data1, Frame -> True]

enter image description here

BubbleChart

As pointed by Edmund, you can use BubbleChart as well. I think it is better.

data2 = data1 /. {{x_, y_}, z_} -> {x, y, z}
BubbleChart[data2]

enter image description here

$\endgroup$
2
  • 1
    $\begingroup$ Have you seen BubbleChart? $\endgroup$
    – Edmund
    Mar 24, 2016 at 12:10
  • $\begingroup$ thanks @Edmund. I did not know about BubbleChart. $\endgroup$
    – Sumit
    Mar 24, 2016 at 12:26
2
$\begingroup$

Colour points in ListPlot using Style and your own colour function with Blend.

SeedRandom[123];
data = RandomInteger[{1, 5}, {100, 2}];

Create a colour function to colour each point. It will take the number of occurrences of the point. The function ranges from 1 to 10 over gray, orange, and blue.

colFunc = Blend[{{0, LightGray}, {.5, Orange}, {1, Blue}}, Rescale[#, {1, 10}]] &;

Use ListPlot's Style wrapper form for the data points. Also include a legend for the colours.

Legended[
 ListPlot[Style[First@#, colFunc[Length@#]] & /@ Gather[data]],
 BarLegend[{colFunc, {1, 10}}, All]]

enter image description here

Hope this helps.

$\endgroup$
1
$\begingroup$

If you have many points, consider SmoothHistogram3D. Borrowing the code from @Sumit to duplicate random points:

data = RandomReal[{0, 10}, {300, 2}];
data = Join[RandomChoice[data, 60], data];

Then

SmoothHistogram3D[data, 0.3]

where the second parameter adjust the sharpness of the smoothing.

SmoothHistogram3D

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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