0
$\begingroup$

I want to plot two data series with the same $x$-Axes. I can use Show for this purpose, but I don't know if it is the best way, because I've to set all options two times (e.g. PlotStyle, PlotMarkers, and so on) As example:

xAxes = {150., 160., 170., 180., 190., 200., 210., 220., 230., 240., 250., 260., 270., 
         280., 290., 300., 310., 320., 330., 340., 350.};
series1 = {-0.02, -0.05, -0.09, -0.14, -0.2, -0.23, -0.23, -0.19, -0.1, -0.01, 0.01, 
           -0.14, -0.57, -1.39, -2.53, -3.64, -3.96, -1.53, 7.05, 29.43, 85.74};
series2 = {0.01, 0.02, 0.01, -0.05, -0.18, -0.43, -0.82, -1.32, -1.88, -2.37, -2.65, 
           -2.58, -2.09, -1.25, -0.27, 0.46, 0.34, -0.82, -2.71, -1.67, 17.65};

gr1 = ListPlot[{xAxes, series1}\[Transpose], PlotMarkers -> Automatic,
PlotStyle -> Black];

gr2 = ListPlot[{xAxes, series2}\[Transpose], PlotMarkers -> Automatic,
PlotStyle -> Red];

Show[gr1, gr2]
$\endgroup$
  • $\begingroup$ In this post, that I read, the solution was with Show. I want to overcome this methodology. Thanks for your comment. $\endgroup$ – Mary Nov 22 '13 at 9:44
  • $\begingroup$ There's another answer there that doesn't use Show. The questions are basically the same, though. $\endgroup$ – Sjoerd C. de Vries Nov 22 '13 at 10:06
  • $\begingroup$ @SjoerdC.deVries I'm not sure if I agree. Linked question is about plotting data series with the same x-Axes, but the main goal here is to make code more compact and how to avoid rewritting options. $\endgroup$ – Kuba Nov 22 '13 at 10:42
2
$\begingroup$

You can allways do

With[{opt={(*options for plots...*)}}
   (*plotting procedures with Plot[..., opt]*)
]

but here are other possibilities:

ListPlot[{{xAxes, series1}\[Transpose], {xAxes, series2}\[Transpose]},
         PlotMarkers -> ●, PlotStyle -> {Red, Black}]

or

ListPlot[{series1, series2}, DataRange -> {150, 350}, PlotMarkers -> ●, 
         PlotStyle -> {Red, Black}]
| improve this answer | |
$\endgroup$
1
$\begingroup$
ListPlot[Transpose[{xAxes, #}] & /@ {series1, series2}, PlotMarkers -> ●, PlotStyle -> {Red, Black}]
| improve this answer | |
$\endgroup$

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