# How can I convert this ListPlot to ArrayPlot?

I want to rewrite this code with ArrayPlot,

n = 10;
eqs = x^Range[0, n - 1].# & /@ Tuples[{-1, 1}, n];
g = ListPlot[{Re@#, Im@#} & /@ Flatten[x /. NSolve /@ eqs]]


just like

ListPlot[Reap[
Do[If[x^2 + y^2 < 500, Sow@{x, y}],
{x, -100, 100}, {y, -100, 100}]][[2, 1]], AspectRatio -> 1]


can be written

ArrayPlot[
Table[If[x^2 + y^2 < 500, 1, 0], {x, -100, 100}, {y, -100, 100}]]


How can I do this?

-
Why would someone do this? Your initial points are on real valued positions, while a raster for ArrayPlot have fixed pixel positions. You will loose information that way! – halirutan Feb 6 '13 at 12:17
Play around a bit with BinCounts and MatrixPlot – ssch Feb 6 '13 at 12:24
@halirutan, I think ArrayPlot worked more faster and easy to set ColorFunction. – chyaong Feb 6 '13 at 13:31
If your question is about setting the ColorFunction to the ListPlot, this is a duplicate of this: mathematica.stackexchange.com/q/1300/5 – R. M. Feb 6 '13 at 15:11

Here is one way:

n = 10;
eqs = x^Range[0, n - 1].# & /@ Tuples[{-1, 1}, n];
data={Re@#,Im@#}&/@Flatten[x/.NSolve/@eqs];
dataBin=Sign@Transpose@BinCounts[data,{-2,2,0.01},{-2,2,0.01}]
ArrayPlot[dataBin]


We get:

Now playing a little with new Mathematica 9 Image3D, we get it rendered for each n, from 1 to 10:

data3D=Table[
eqs=x^Range[0,n-1].#&/@Tuples[{-1,1},n];
data={Re@#,Im@#}&/@Flatten[x/.NSolve/@eqs];
Sign@Transpose@BinCounts[data,{-2,2,0.01},{-2,2,0.01}]
,{n,1,10}]//Quiet;

Image3D[data3D, BoxRatios -> {1, 1, 1}]


Much more cool! :)

-
@chyanog Hi! Thank you for the accept. – Murta Feb 8 '13 at 2:31

I would not use ArrayPlot because it expects a matrix while you have free point positions. In the processing of pressing the real valued positions on a grid, you will lose information.

@halirutan, I think ArrayPlot worked more faster and easy to set ColorFunction.

When your goal is to colorize your points and you think setting the ColorFunction in ListPlot is too slow, why don't you plot your points manually? I assume doing something like

n = 10;
eqs = x^Range[0, n - 1].# & /@ Tuples[{-1, 1}, n];
data = {Re@#, Im@#} & /@ Flatten[x /. NSolve /@ eqs];

Graphics[Point[data]]


can never be slower than calling ListPlot. Now you want to colorize each point which means you want to transform a point {x,y} into a color like {r,g,b}. Let's say you try to make this function as fast as possible, because it is called very often with many points. Therefore, you use Compile in a parallel fashion. One simple example would be

colfunc = Compile[{{point, _Real, 1}},
.5*{Sin[point[[1]]], -Sin[point[[2]]], Cos[point[[2]]]} + .5,
Parallelization -> True, RuntimeAttributes -> {Listable}
]


And then you see that you can give a list of colors to Point, colorizing each point differently when you use the option VertexColors:

Graphics[Point[data, VertexColors -> colfunc[data]]]


This runs in no time compared to your NSolve call, which is about 1000 times slower!

-