0
$\begingroup$

I have a general {i,x,y} dimensional matrix, and I want to plot all "i" {x,y} matrices in one graph. How can I do it in a way that I can still distinguish each "i"th curve from the other (I mean creating curves with different colors using plot).

This a example of a code I written, but since I used table to create a loop I couldn't distinguish the curves:

a = Table[Random[], {i, 1, 4}, {x, 1, 6}, {y, 1, 5}];

Show[Table[
aFxn = ListInterpolation[(Chop[a[[i + 1]]] - Chop[a[[i]]])];
Table[aFxn[\[Theta], \[Phi]], {\[Theta], 1, 6}, {\[Phi], 1, 5}];
Plot[Abs[aFxn[3, \[Phi]]], {\[Phi], 1, 5}, 
PlotLegends -> {Subscript[Ne, i]}, PlotRange -> All, 
AxesLabel -> {Ne, spinupcoefficient}], {i, 1, 3}]]

My real matrices have higher dimensions, so I can not use Plot[{},{},{},..] to create the different colors.

I would be thankful if somebody could help me with this.

$\endgroup$

1 Answer 1

1
$\begingroup$

Here is one option:

curves = Table[
   aFxn = ListInterpolation[(Chop[a[[i + 1]]] - Chop[a[[i]]])];
   Abs[aFxn[3, ϕ]]
   , {i, 1, 3}];

Plot[curves, {ϕ, 1, 5}, 
 PlotLegends -> Table[Subscript[Ne, i], {i, 1, 3}]]

enter image description here

Another option:

curve[i_] :=
 ListInterpolation[(Chop[a[[i + 1]]] - Chop[a[[i]]])]

Plot[Evaluate@Table[Abs[curve[i][3, ϕ]], {i, 1, 3}], {ϕ, 1, 5}, 
 PlotLegends -> Table[Subscript[Ne, i], {i, 1, 3}]]

same image

$\endgroup$
6
  • $\begingroup$ Thank you, I guess that's what I want $\endgroup$ Commented Jul 24, 2019 at 23:26
  • $\begingroup$ How to do I show the plotlegends for different colors corresponding to different "i"s? $\endgroup$ Commented Jul 25, 2019 at 3:28
  • $\begingroup$ I want sth like PlotLegends -> {Subscript[Ne, i]} , corresponding to each i $\endgroup$ Commented Jul 25, 2019 at 3:30
  • $\begingroup$ adding plot legend after {[Phi], 1, 5} doesn't work for me $\endgroup$ Commented Jul 25, 2019 at 3:34
  • 1
    $\begingroup$ @DelaramNematollahi Updated answer to include PlotLegends. $\endgroup$
    – MelaGo
    Commented Jul 25, 2019 at 3:37

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.