2
$\begingroup$

I am about to plot eigenvalues of a matrix versus varyingj's.

Hma[j_Integer] = {{0.1*j^2, 0, 0, 0.2*j, 0}, {0, 0.1*j, 0, 0.2*j^3, 
0}, {0, 0.1*j, 0, 0, 0.2*j}, {0.1*j^2, 0, 0, 0, 0.2*j}, {0, 0, 
0.1*j, 0.2*j, 0}};
data=Flatten[Table[Thread[{j, Re@Eigenvalues[Hma[j]]}], {j, n}], 1];
ListPlot[data]

enter image description here

I am trying to have a plot with specified color as I manually showed above. (higher eigenvalues (first ones) with a same color (for example Red above), seconds with same color (and different from the first ones for example Yellow))

$\endgroup$
0
3
$\begingroup$

For the data in the question, the following also works.

ListPlot[Transpose[Split[data, First[#1] === First[#2] &]], 
    PlotStyle -> {Blue, Green, Purple, Orange, Red}]

enter image description here

This, of course, assumes that data already is ordered by size. If not, use

ListPlot[SortBy[Transpose[Split[data, First[#1] === First[#2] &]], Last],
    PlotStyle -> {Blue, Green, Purple, Orange, Red}]

And, if larger markers (or other such presentation changes) are desired, use

ListPlot[SortBy[Transpose[Split[data, First[#1] === First[#2] &]], Last], 
    PlotStyle -> ({#, PointSize[Large]} & /@ {Blue, Green, Purple, Orange, Red})]

enter image description here

Note that the Green points are scarcely visible, because they approximately coincide with the Purple points.

$\endgroup$
3
$\begingroup$

How about this:

 n=5;
 dt = Table[Select[SortBy[data, Last], #[[1]] == j &], {j, 1, n}];

 ListPlot[Table[dt[[1 ;; n, eid]], {eid, 1, 5}], 
  PlotStyle -> {Blue, Green, Purple, Orange, Red}]

enter image description here

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.