I have a list of (x,y) points I would like to plot with each point a specific color. ListPlot is substantially slower when I assign each point a color than when I use the default single color for each point.
Any idea on how to speed up?
Below is test code where I have assigned one of four colors randomly. Note the timing.
Thanks.
n = 10^4;
locs = Table[{RandomReal[] , RandomReal[]} , n];
c = RandomChoice [ {Red, Green, Blue, Black} , n];
t0 = TimeUsed[];
p1 = ListPlot[locs, ImageSize -> 800];
t1 = TimeUsed[];
p2 = ListPlot[List /@ locs, ImageSize -> 800, PlotStyle -> c];
t2 = TimeUsed[];
Print [ "All same color = ", t1 - t0 , " cpu seconds." ];
Print["Each point its own color = " , t2 - t1 , " cpu seconds." ];
All same color = 0.115 cpu seconds. Each point its own color = 7.015 cpu seconds
Timing
(orAbsoluteTiming
) to measure how much time it takes to execute some command. For example,p1 = ListPlot[locs, ImageSize -> 800]; // AbsoluteTiming
yields0.1
seconds andp2 = ListPlot[List /@ locs, ImageSize -> 800, PlotStyle -> c]; // AbsoluteTiming
yields9.3
seconds. No need to use thatt0 = TimeUsed[];
trickery. $\endgroup$Graphics[Point[locs, VertexColors -> c], Options@ListPlot]
? What you lose is automaticPointSize[]
determination.... $\endgroup$