3
$\begingroup$

I have some discrete data in the form {{x1,y1},{x2,y2},...} and when I produce a ListLogLogPlot they look like this:

2D discrete data

I would like to produce a density plot or map saying, how much packed the points are (I am not really sure, how this should be achieved though, my first idea is take a circle of a fixed radius centered on a given point and count how many neighbours there are and based on that assign value/colour but maybe this is nonsense). I found the most likely candidate to be SmoothDensityHistogram but it produces this (I admit, I do not understand this function much, I read help, but there everything works perfectly however they generate the data syntetically):

SmoothDensityHistogram result

But if I look at the first plot, quite obviously the plot I want should look like "a hot area in the center with tails to the north and east". There is an ovious another issue, how to force log scales to SmoothDensityHistogram, because when I use

SmoothDensityHistogram[smbdataSpin[[All, 1 ;; 2]], 0.1, 
  ScalingFunctions -> {Log, Log}]

I get something even more strange:

SmoothDensityHistogram result with log scaling

The data that produce the first plot can be obtained here.

$\endgroup$
5
  • $\begingroup$ Have you looked at ListDensityPlot? $\endgroup$
    – Carl Woll
    Commented May 2, 2017 at 22:18
  • $\begingroup$ @CarlWoll I know of it but unless I am missing something, that constructs the density from the values of the array which in my case makes little sense I think because e.g. {{1,1},{2,2}} would have the highest value of density in the top right corner but that is incorrect as it says nothing about the density of points in the plot. $\endgroup$
    – atapaka
    Commented May 2, 2017 at 22:46
  • $\begingroup$ My bad. I think that SmoothDensityHistogram should work, but there seems to be an issue with the ScalingFunctions option. $\endgroup$
    – Carl Woll
    Commented May 2, 2017 at 23:02
  • $\begingroup$ If the set of points is a simple random sample from a bivariate probability distribution, you should try SmoothKernelDistribution[smbdataSpin[[All, 1 ;; 2]]]. $\endgroup$
    – JimB
    Commented May 3, 2017 at 0:02
  • $\begingroup$ Another approach is hexagon binning: mathematica.stackexchange.com/questions/28149/…. $\endgroup$
    – JimB
    Commented May 3, 2017 at 0:05

2 Answers 2

8
$\begingroup$

Possibly the following is what you're looking for?

SmoothDensityHistogram[
    Log @ data,
    Frame->True,
    PlotRange->All,
    FrameTicks -> {
        {Charting`ScaledTicks[{Log, Exp}], Charting`ScaledFrameTicks[{Log, Exp}]},
        {Charting`ScaledTicks[{Log, Exp}], Charting`ScaledFrameTicks[{Log, Exp}]}
    }
]

enter image description here

$\endgroup$
6
$\begingroup$

You can also do this in 3D

ticks = {
    Table[{n, 10^n}, {n, -3, 3}],
    Table[{n, 10^n}, {n, -2, 3}],
    Automatic} /. r_Rational :> N[r];

Histogram3D[Log10[data],
 Ticks -> ticks,
 ColorFunction -> Function[{height}, ColorData["TemperatureMap"][height]]]

enter image description here

SmoothHistogram3D[Log10[data],
 Ticks -> ticks,
 ColorFunction -> 
  Function[{x, y, height}, ColorData["TemperatureMap"][height]]]

enter image description here

$\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.