-9
$\begingroup$

I am calculating eigenvlaues. Some are negative, some are positive. I define the index nn and mm (as well as np and mp) of each matrix element by some functions that assign positive, zero and negative integer values for nn (np) and strictly positive integers for mm (mp). My code is much more complex, but a simplified version of it looks like this:

nn = 2; mm = 3; som = 2 (nn + 1) mm; RX = 1; PO = 5;
n[a_] := Floor[(a - 1)/mm] - Floor[(a - 1)/((nn + 1) mm)] - nn; 
m[a_] := Mod[a - 1, mm] + 1;
np[b_] := Floor[(b - 1)/mm] - Floor[(b - 1)/((nn + 1) mm)] - nn; 
mp[b_] := Mod[b - 1, mm] + 1;
Vnozer[nn1_, np1_, mm1_, 
   mp1_] := (2 nn1 + 3 np1 + 4 mm1 + 5 mp1) Exp[kx];
Vzer[nn1_, np1_, mm1_, 
   mp1_] := (-4 nn1 - 3 np1 - 2 mm1 - 1 mp1) Exp[kx];
V[nn1_, np1_, mm1_, mp1_] := 
  If[Abs[nn1] > 0 && Abs[np1] > 0, Vnozer[nn1, np1, mm1, mp1], 
   Vzer[nn1, np1, mm1, mp1]];
EN[nn1_] := Sign[nn1] Sqrt[Abs[nn1]];
c[a_, b_] := 
  EN[n[a]] KroneckerDelta[Abs[n[a]], Abs[np[b]]] KroneckerDelta[m[a], 
     mp[b]] KroneckerDelta[Sign[n[a]], Sign[n[b]]] + 
   V[n[a], np[b], m[a], mp[b]];
Q = Array[c, {som, som}];
MF = Table[{kx, Eigenvalues[Q]}, {kx, -RX, RX, (2 RX)/(PO - 1)}];
Array[ou, som]; Array[pl, som];
Table[ou[y] = Table[{MF[[x, 1]], MF[[x, 2]][[y]]}, {x, 1, PO}], {y, 1,
    som}];
Table[pl[y] = ListPlot[ou[y], PlotRange -> All], {y, 1, som}];
FPL = Table[pl[z], {z, 1, som}];
Show[FPL]

Eigenvalue plot looks like this.

I would like to get Red PlotMarkers when my eigenvalues are positive and, say, Blue when my eigenvalues are negative. I played around with an If statement, but I was not able to figure out the right syntax. Something along the lines

PlotMarkers->{If[x]>0, {Red, dotsize}, {Blue, dotsize}}
$\endgroup$
2
  • $\begingroup$ your code doesn't work on my computer (hanging) $\endgroup$
    – andre314
    Feb 24, 2013 at 23:19
  • 1
    $\begingroup$ pts = RandomInteger[{-10, 10}, 100]; ListPlot@GatherBy[pts, Positive] $\endgroup$
    – ssch
    Feb 24, 2013 at 23:22

2 Answers 2

1
$\begingroup$
 lp = ListPlot[Table[ou[y], {y, 1, som}],
 PlotRange -> All, PlotMarkers -> {Automatic, Medium},
 Joined -> True, ImageSize -> 500]

enter image description here

Post-process to change the colors of markers:

 Normal[lp] /. Inset[a_, {x_, y_}] :> Sequence[If[y >= 0, Red, Blue], Inset[a, {x, y}]]

enter image description here

$\endgroup$
2
$\begingroup$

Perhaps (I saw later that ssch commented a solution around the same lines above):

ListPlot[GatherBy[Flatten[Table[ou[y], {y, 1, som}], 1], Positive[#[[2]]] &], 
   PlotStyle -> {Red, Blue}]

Mathematica graphics

$\endgroup$
4
  • $\begingroup$ This looks good in terms of positive eigenvalues being colored red, negatives being colored blue. What I really want to accomplish is to plot in red all eigenvalues that come from matrix elements labeled by nn (np) values that are positive and plot blue the eigenvalues that are labeled by nn (np) values that are negative (I will then have to deal with nn=0, but that is the next step). The eigenvalue itself may be positive OR negative. This is why I thought an If statement may be the way to go. Perhaps I should have suggested PlotMarkers->{If[nn]>0&&[np]>0, {Red, dotsize}, {Blue, dotsize}} $\endgroup$ Feb 24, 2013 at 23:45
  • 6
    $\begingroup$ @RainforestFrog But that is not what you said in the question... $\endgroup$
    – rm -rf
    Feb 25, 2013 at 0:00
  • $\begingroup$ @rm-rf I quit .. $\endgroup$ Feb 25, 2013 at 0:47
  • 4
    $\begingroup$ @RainforestFrog i hope you appreciate that it is frustrating for people who contribute time and expertise to offer an answer to a specific question only to be confronted with details or "what ifs" not previously mentioned in the question. It creates frustration and ill will and makes it less likely that you will get positive replies to your questions in the future. $\endgroup$ Feb 25, 2013 at 2:36

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.