2
$\begingroup$

I have a list of points:

r = Range[-Pi/2, Pi/2, Pi/8];
angles = (c = Tuples[r, 2])

and a list of numbers which will determine the colour of the points above:

times = {12.5, 23.9, 3.7, 10.5, 6.7, 7.1, 20.2, 6.5, 11.7, 1.3, 29.8, 4.8, 
7.3, 19.5, 3.7, 19.3, 24.9, 11., 1.4, 6.6, 14.5, 23.2, 18.8, 23.2, 
17.1, 22.3, 5.2, Null, 7.5, 19.3, 23.5, 15.2, 17.6, 16.3, 11.7, Null, 
10.3, 13.6, 3.6, 3.4, 10., Null, Null, 25.5, 11.4, 4.9, 5.2, 24.3, 
9., 29.9, 7.5, Null, 9.1, 12.6, Null, 7.9, 13.2, 8.4, 9.8, Null, 20., 
24.3, 14.1, 3.7, 7.6, 18., 7.8, 8.8, 15.9, Null, 16.8, 13.3, 6.9, 
12.5, 3.3, 9.1, 7.1, 15.6, 9.5, 13.5, 12.1}

To turn these into colours, I do this:

colours = 
 times /. {x_ /; x < 3 -> Darker[Green], x_ /; 3 <= x < 6 -> Green, 
   x_ /; 6 <= x < 9 -> Darker[Red], x_ /; 9 <= x < 12 -> Red, 
   x_ /; 12 <= x < 20 -> Darker[Yellow], 
   x_ /; 20 <= x < 30 -> Lighter[Yellow], x_ /; 30 <= x -> White, 
   x_ /; x === Null -> White}

Now I want to plot angles, where the colour of each point is the based on the list colours.

This is what I tried:

ListLinePlot[angles, ColorFunction -> colours, AspectRatio -> 1, 
  PlotStyle -> PointSize[.1]] /. Line -> Point

enter image description here

And that's not correct. It doesn't help that I am red-green colourblind so it's REALLY annoying. I've also fooled around with ColorRules and MatrixPlot but can't seem to get anything going. Any helpful hints or ideas?

$\endgroup$

2 Answers 2

5
$\begingroup$
ListPlot[MapIndexed[Style[#, colours[[#2]], PointSize[.1]] &, angles], AspectRatio -> 1]

or

ListPlot[Style[#, #2, PointSize[.1]] & @@@ Transpose[{angles, colours}], AspectRatio -> 1]

enter image description here

Update:

make those circles into squares, and make them all fill up the plot? As in no spaces between each one

ArrayPlot[Transpose@Partition[colours, 9], AspectRatio -> 1, 
 DataReversed -> True, Frame -> False]

enter image description here

$\endgroup$
2
  • $\begingroup$ Thanks very much. Do you know if there's a way in ListPlot to make those circles into squares, and make them all fill up the plot? As in no spaces between each one? $\endgroup$ Nov 30, 2014 at 11:38
  • $\begingroup$ @LonelyMathematician, i think ArrayPlot is easier for this particular case: e.g., try ArrayPlot[Transpose@Partition[colours, 9], AspectRatio -> 1, DataReversed -> True]. $\endgroup$
    – kglr
    Nov 30, 2014 at 12:10
5
$\begingroup$

Another way to draw rectangles using Graphics:

Graphics[MapThread[{#2, Rectangle[#1, #1 + π/8]} &, {angles, colours}]]

Mathematica graphics

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