I would like to plot a graph of a random-generated list of points, so that they decay a little bit by moving from the origin. So far I wrote this piece of code, which seems to give me the desired output:
ClearAll[Evaluate[$Context <> "*"]]
MAXITER = 10;
Array[f, MAXITER, 0];
For[i = 0, i < MAXITER, i++,
ppXst = 1/(i + 1) * 1000;
v = i/MAXITER;
strip = 2/MAXITER;
If[i == 0, strip == Abs[strip]];
CircularDistribution[num_] :=
Table[{Sqrt[RandomReal[{If[i == 0, .05, v], v + strip}]] {Cos[#],
Sin[#]} & //@ Random[Real, {0, 2 Pi}]}, {num}];
f[i] = ListPlot[
CircularDistribution[ppXst],
AspectRatio -> 1,
ImageSize -> Medium,
Axes -> False,
PlotStyle -> {{Gray, Opacity[.4], PointSize[.01]}}
];
];
Show[
{Table[f[i], {i, 0, MAXITER - 1}],
Graphics[{Red, PointSize[.02], Point[{0, 0}]}]},
PlotRange -> All,
ImageSize -> Large
]
Now, what I really need is to color the points depending on the distance between them and the origin. The problem is that I did't find out a way to access the single point distance from the origin in the Show
command, nor I can figure out how to color ListPlot
by ListPlot
in order to obtain an uniform coloured plot depending on the distance of the single point. I only get near what I want by doing so:
MAXITER = 10;
Array[f, MAXITER, 0];
For[i = 0, i < MAXITER, i++,
ppXst = 1/(i + 1) * 1000;
v = i/MAXITER;
strip = 2/MAXITER;
If[i == 0, strip == Abs[strip]];
CircularDistribution[num_] :=
Table[{Sqrt[RandomReal[{If[i == 0, .05, v], v + strip}]] {Cos[#],
Sin[#]} & //@ Random[Real, {0, 2 Pi}]}, {num}];
f[i] = ListPlot[
CircularDistribution[ppXst],
AspectRatio -> 1,
ImageSize -> Medium,
Axes -> False,
PlotStyle -> {{Hue[v], Opacity[.4], PointSize[.01]}}
];
];
Show[
{Table[f[i], {i, 0, MAXITER - 1}],
Graphics[{Red, PointSize[.02], Point[{0, 0}]}]},
PlotRange -> All,
ImageSize -> Large
]
which is not really what I want, as it's coloured per strip and not per single point distance.
Also, if it's possible, I would like to superimpose to the final graph a Legend
, similar to the color map of the ContourPlot
which is easily achievable with PlotLegends-> Automatic
, to show the distance associated to the color.