0
$\begingroup$

If I have multiple variables y1, y2, y3, y4 for y-axis and phi values for x-axis, then how do I plot these variables, indicating each variable with different black marker? My code is

data=Import["simavg1.xls",{"Data",1}]; 
phi=data[[All,1]]; 
csrp=data[[All,2]]; 
crl=data[[All,3]]; 
cArp=data[[All,4]]; 
Plot[{csrp,crl,cArp},phi]

but does not work.

$\endgroup$
5
  • $\begingroup$ Have a look at Plot. $\endgroup$ Commented Feb 17, 2016 at 13:01
  • $\begingroup$ dear look but unable to enter phi values on x-axis. my commands are data=Import["simavg1.xls",{"Data",1}]; phi=data[[All,1]]; csrp=data[[All,2]]; crl=data[[All,3]]; cArp=data[[All,4]]; Plot[{csrp,crl,cArp},phi] $\endgroup$
    – Amin
    Commented Feb 17, 2016 at 13:03
  • 1
    $\begingroup$ Consider using ListPlot. $\endgroup$
    – bbgodfrey
    Commented Feb 17, 2016 at 13:19
  • $\begingroup$ have you seen Customizing a graph (Dashing, PlotMarkers, Labeled) $\endgroup$
    – user9660
    Commented Feb 17, 2016 at 13:34
  • $\begingroup$ Also consider PlotTheme -> "Monochrome" if you are using a recent version of Mathematica, e.g. ListLinePlot[ Table[{k, PDF[BinomialDistribution[50, p], k]}, {p, {0.3, 0.5, 0.8}}, {k, 0, 50}], Filling -> Axis, PlotLegends -> {0.3, 0.5, 0.8}, PlotTheme -> "Monochrome"] $\endgroup$
    – Mr.Wizard
    Commented Feb 17, 2016 at 17:49

1 Answer 1

3
$\begingroup$

What you need to do is take each of your lists of y-values into a list of {x, y} pairs. To do this, you Transpose each of them with the phi list. This would work,

ListPlot[Transpose[{phi, #}] & /@ {csrp,crl,cArp}]

But if all of your lists are initially in the data array, then all you should have to do is define the lists including the x-values from the getgo,

csrp=data[[All,{1,2}]]; 
crl=data[[All,{1,3}]]; 
cArp=data[[All,{1,4}]];

and now you can just use

ListLinePlot[{csrp,crl,cArp}]
$\endgroup$
4
  • $\begingroup$ dear how to change the dashed colors and plot legends above the graph in this command ListLinePlot[{csrp,crl,cArp},Frame->True,FrameLabel->{Style["[Phi]",Black,Bold],Style["Average (%) Influence Detection",Black,Bold]},PlotLegends->{"\!(*SubscriptBox[(D), ([Chi])])","\!(*SubscriptBox[(D), (l)])","\!(*SubsuperscriptBox[(D), ([Chi]), (A)])"},PlotStyle->{Dashing,Dotted,Dashed},PlotLabel->"(a) n=50"] $\endgroup$
    – Amin
    Commented Feb 17, 2016 at 15:53
  • $\begingroup$ @Amin try something like PlotStyle -> {{Red, Dashed}, {Blue, Dotted}, {Purple, Dashed}} $\endgroup$
    – Jason B.
    Commented Feb 17, 2016 at 15:59
  • $\begingroup$ Thanks and what about plot legends position on the graph instead of Right side? $\endgroup$
    – Amin
    Commented Feb 17, 2016 at 17:20
  • $\begingroup$ Dear How I plot this data with respective axis labels $\endgroup$
    – Amin
    Commented May 18, 2016 at 1:00

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