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.


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


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

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

enter image description here

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

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

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.

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

enter image description here

Hope this helps.


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];


SmoothHistogram3D[data, 0.3]

where the second parameter adjust the sharpness of the smoothing.



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.