Before I describe the question, I'd like to say that I've seen the excellent answers posted here but have not managed to get them to work for my own data.
I have a list of values that I would like to plot in polar coordinates. The values represent the position of a series of coupled pendulums, and as such while the angle changes the radius does not. Here is a sample of the data for the pendulums, at a certain time t
.
position = {
{-1.25084, 1}, {-1.42995, 1}, {-1.7497, 1}, {-1.83175, 1}, {-1.733,1}, {-1.86803, 1},
{-1.79935, 1}, {-1.87909, 1}, {-1.78354, 1}, {-1.81614, 1}, {-1.58559, 1}, {-1.71751, 1},
{-1.72079, 1}, {-1.60622, 1}, {-1.72122, 1}, {-1.46695, 1}, {-1.62577, 1}, {-1.75079, 1},
{-0.89456, 1}, {-0.950143, 1}, {-1.5654, 1}
}
What I would like to do is to color each of the pendulum based on their position; that is, the first pendulum (with angle -1.25084) would be colored purple, the next (with angle -1.42995) slightly purplish-blue and all the way to the last pendulum (with angle -1.5654) being colored red.
The purpose of coloring the pendulums as such is that, as I vary time t
using Manipulate
, I would then be able to track the pendulums by their color.
My attempt at this is below, but somehow it doesn't work in the way I intend it to.
n = Length[Transpose[position][[1]]]
position = Transpose[{Transpose[position][[1]], (1 + 0.001*Range[n]/n)}];
(* adding a small modifier to the radius of each pendulum to allow me to
identify the specific pendulum and give it a color later *)
pendulumcolor = ColorData["Rainbow"][1000*(#2 - 1)] &;
(* defining a colour function that extracts the pendulum number and relates
it to a color *)
ListPolarPlot[position,
PlotRange -> {{-1, 1}, {-1, 1}},
PlotStyle -> Thick,
Joined -> True,
ColorFunction -> pendulumcolor] /.
Line[a__] :> {AbsolutePointSize[8], Point[a]}
My output looks something like this, which is definitely not what I intended. The colors of each point should be different, rather than being all red.
Edit:In response to VLC's request, a sample of my code is provided below.
n = 100;
(* n is the number of pendulums in our system *)
pendulumplotstyle =
Table[Directive[PointSize[Large], ColorData["Rainbow"][Mod[i, 10]/10]], {i, 0, n}];
(* every ten pendula are coloured to span the color of the rainbow *)
Manipulate[
ListPolarPlot[List /@ funcposition[tdummy],
PlotRange -> {{-1, 1}, {-1, 1}},
PlotStyle -> pendulumplotstyle],
{tdummy, 0, 10, 0.001}]
In the above code, we have a function funcposition[t]
that gives the position of the pendulums as a function of time t
. This function is a numerical solution to an ODE that I'd rather not put up because of the length. The code will not work as-is due to the presence of funcposition[t]
but it should give a good idea of what I'm doing.
n
somewhere else in the kernel and didn't spot the problem. $\endgroup$Transpose[position][[1]]
you can get the same result withposition[[All, 1]]
. $\endgroup$n = Length[position]
will always work. So why bother withn = Length[Transpose[position][[1]]]
? $\endgroup$Manipulate
function. Take a look also at Mr.Wizard's solution to speed up rendering ofListPolarPlot
. $\endgroup$