# Plotting Energies vs. m for all values of R with the colors of the levels indexed by R [closed]

I have two lists like this:

 m=0:
Lm0R250={0.59121,0.4211,0.8507,0.9636}
Lm0R200={0.1246,0.345953,0.67831}
Lm0R150={0.1252422,0.25837}
Lm0R100={0.2357,0.345}
Lm0R50={0.12525}

m=1:
Lm1R250={0.45237,0.670137,0.894342}
Lm1R200={0.59951,0.59403}
Lm1R150={0.86613,0.259408}
LmR100={0.157144}


These lists are energies corresponds to m value which is a parameter in my code. But each list correspond to different R. I want to plot Energies vs. m values. m goes from zero to 3. These data are only for m=0 and m=1. I want a Floor plot. Could anyone please help me to do that.

-
What have you tried? If we can see that someone might be able to decipher what the question is. – chuy Mar 6 at 16:00
So it looks like you 2 degrees of freedom then. R and m are the independent variables, and the dependent variable is the energy. So your energy(R,m) is a function. So you need 3D plot. The x-axis will be R and the y-axis will be m, and the z-axis is energy(R,m). There are many ways to make 3D plots in M depending on how you want to visualize the result. – Nasser Mar 6 at 16:06
I want to plot a graph like above. – TMH Mar 6 at 21:20
If you are going to draw energy levels, it's worth looking at the popular LevelScheme package. – Szabolcs Mar 6 at 21:27
@Thakshila Please try reading the question as if you don't know what's being asked. Do you really think it's actually understandable? What is R? What do I have to do to get the 3 numbers you plotted for m=0 from the 12 numbers you gave for m=0? – acl Mar 6 at 21:30

## closed as not a real question by acl, Oleksandr R., m_goldberg, rcollyer, Verbeia♦Mar 7 at 4:27

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, see the FAQ.

I don't think the question is so terribly bad. But the data representation makes the problem awkward to understand and solve. First I put your data in another form, {m, R, E}:

$m = Range[0, 3]; (* domain for m *)$R = Range[50, 250, 50]; (* domain for R *)

L[m_, R_] := If[Head[#] === Symbol, {}, #] &@
Symbol["Lm" <> ToString[m] <> "R" <> ToString[R]];
energyData = Flatten[Table[Thread[{m, R, L[m, R]}], {m, $m}, {R,$R}], 2]


If you don't understand the code, don't worry (see addendum). Look at the output below. This is how you might represent your data better; enter it this way, if you can.

{{0, 50, 0.186825}, {0, 100, 0.121567}, {0, 100, 0.2715},
{0, 150, 0.0992422}, {0, 150, 0.195237}, {0, 200, 0.0888446},
{0, 200, 0.153953}, {0, 200, 0.24331}, {0, 250, 0.083121},
{0, 250, 0.130411}, {0, 250, 0.197507}, {0, 250, 0.274236},
{1, 100, 0.184144}, {1, 150, 0.136613}, {1, 150, 0.251408},
{1, 200, 0.113951}, {1, 200, 0.19403}, {1, 250, 0.101237},
{1, 250, 0.160137}, {1, 250, 0.234342}}


I assumed you wanted to plot the levels for each value of R separately. So I defined a function to select out the data with a given R value:

en[R_] := Cases[energyData, x : {_, R, _} :> Drop[x, {2}]]


For example:

en[250]

{0, 0.083121}, {0, 0.130411}, {0, 0.197507}, {0, 0.274236},
{1, 0.101237}, {1, 0.160137}, {1, 0.234342}}


Then you can use ListPlot with a special PlotMarker that is a red line graphic:

With[{R = 250},
ListPlot[en[R],
PlotMarkers -> {Graphics[{Red, Thick, Line[{{-1/2, 0}, {1/2, 0}}]}], 0.5},
PlotRange -> {{-0.5, 3.5}, {0, Automatic}},
Frame -> {{True, False}, {True, False}}, Axes -> False,
FrameTicks -> {{Automatic, None}, {$m, None}}]]  Edit: Incorporating @rcollyer's solution I misunderstood the question, and this seems to get at the original intention to combine the plots for each value of R: ListPlot[GatherBy[energyData, #[[2]] &][[All, All, {1, 3}]], PlotMarkers -> {Graphics[{Thick, Line[{{-1/2, 0}, {1/2, 0}}]}], 0.5}, PlotRange -> {{-0.5, 3.5}, {0, Automatic}}, Frame -> {{True, False}, {True, False}}, Axes -> False, FrameTicks -> {{Automatic, None}, {$m, None}}]


Addendum: The strange function L above

The original energy levels were stored in variables with names that seemed to be in the form:

LmxRyyy = {E1, E2,...}


where x was the corresponding value of m (0, 1, etc.) and and yyy was the corresponding value of R (50, 100, etc.). The idea was to convert these into a single list of elements of the form {m, R, E}, one for each energy level with its corresponding m and R. To do this, I wanted a function L that, for m = x and R = yyy, would return LmxRyyy. At first glance this seems to work:

L[m_, R_] := Symbol["Lm" <> ToString[m] <> "R" <> ToString[R]];


For instance L[0, 150] returns Symbol["Lm0R150"] which is the same as the variable Lm0R150.

So far, so good. If Lm0R150 is defined, then evaluation of L[0, 150] will be the list of energies. The difficulty arise when the variable is undefined. L[1,50] returns the symbol Lm1R50, which is undefined. I wanted the default to be an empty list, so I added a test in the form of a pure function:

L[m_, R_] := If[Head[#] === Symbol, {}, #] &@
Symbol["Lm" <> ToString[m] <> "R" <> ToString[R]];


If the Head of the evaluated Symbol["Lm" <> ToString[m] <> "R" <> ToString[R]] is still Symbol, then the corresponding variable is undefined and {} is returned; otherwise the variable is return. (In the pure function If[...]&, the # is replaced by the Symbol[...] expression. f@expr is the prefix form of f[expr].)

To understand how L is used to make energyData, one should probably start by evaluating

Thread[{x, yyy, {1, 2, 3}}]
(* -> {{x, yyy, 1}, {x, yyy, 2}, {x, yyy, 3}} *)


It creates a list of the form {m, R, E}. These are then collected in a table, which is flattened.

energyData = Flatten[Table[Thread[{m, R, L[m, R]}], {m, $m}, {R,$R}], 2]


$m and $R were defined to contained all the apparent values of m and R, so that the table would include all possible combinations, and energyData would contain all data.

Now

en[R_] := Cases[energyData, x : {_, R, _} :> Drop[x, {2}]]


finds all cases of triples in energyData whose second element is R and drops the second element. The result is a list of elements of the form {m, E}, exactly those for the given value of R.

Note: I changed LmR100={0.157144} in the original question to Lm1R100={0.157144}, which I took to be a typo.

-
Thanks a lot Michael. However at this moment, what I want to do is plot E vs m for all values of R. Actually, I tried myself and finally did it.But my method is very long. Here you used some efficient methods. So, I will post my current plot. Could you please look at it and tell me an efficient way to plot it? – TMH Mar 7 at 3:15
@TMH "Actually, I tried myself and finally did it.But my method is very long. " — please add your method to your question. Without that, it's impossible for anyone to tell you if you are doing it inefficiently, which is what your comment above asks for. – rm -rf Mar 7 at 3:35
@TMH To plot them all at once, I would do two things. First, remove Red from the line with PlotMarkers in the above answer (be sure to get the comma after it, too). Second, I would use GatherBy[energyData, #[[2]] &][[All, All, {1, 3}]] in place of en[R]. – rcollyer Mar 7 at 3:36
@rcollyer Thanks a lot. That works very well. – TMH Mar 7 at 3:51
@TMH Yes, the second example uses the same data as the first. – Michael E2 Mar 7 at 12:14