2
$\begingroup$

I am trying to build band structures and am looking to generate a general code that will work regardless of my list size. Here is what I am trying to do: say I have a list like

list = {{0.0, 1, 2, 3}, {0.1, 4, 5, 6}, {0.2, 7, 8, 9}, {0.3, 10, 11, 12}};

and I want to plot the nth element of each list against the first element of each list. How can I tell Mathematica to automatically produce a set of lists to plot like shown below

k = {0.0, 0.1, 0.2, 0.3};
band1 = {1, 4, 7, 10};
band2 = {2, 5, 8, 11};
band3 = {3, 6, 9, 12};
Show[ListLinePlot[k, band1], ListLinePlot[k, band2], ListLinePlot[k, band3]]

Doing it manually one band at a time is possible but a waste of time when I have n=36+ bands. Any help would be much appreciated!

$\endgroup$
1
  • 1
    $\begingroup$ E.g. band[k_]=(Transpose@list)[[k-1]] $\endgroup$
    – Artes
    Sep 12, 2020 at 14:28

1 Answer 1

4
$\begingroup$
Clear["Global`*"]

plot[list_?MatrixQ] := Module[
  {k = list[[All, 1]],
   bands = Transpose[list[[All, 2 ;;]]]},
  ListLinePlot[Transpose[{k, #}] & /@ bands,
   PlotLegends -> Range[Length[bands]],
   AxesLabel -> {"k", "bands"}]]

list = {{0.0, 1, 2, 3}, {0.1, 4, 5, 6}, {0.2, 7, 8, 9}, {0.3, 10, 11, 12}};

plot[list]

enter image description here

$\endgroup$
1
  • $\begingroup$ Perfect! Many thanks :) $\endgroup$ Sep 12, 2020 at 15:13

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.