4
$\begingroup$

I need to have a plot with different colors for each data. Since I couldn't have all the data in one Plot with different colors, I drew each separately and used the Show command for the overall display, but one of the data does not appear in the final Plot and I don't know where the problem is?!

Needs["ErrorBarPlots`"]
val1 = ImportString["0.12    10   0.01   0
0.12    10   0.01   0"];
val2 = ImportString["0.12    20   0.01   0
0.12    20   0.01   0"];
val3 = ImportString["0.12    30   0.01   0
0.12    30   0.01   0"];

p1 = ErrorListPlot[{{#1, #2}, ErrorBarPlots`ErrorBar @@ {#3, #4}} & @@@
val1, IntervalMarkersStyle -> Thick, PlotStyle -> Red, 
PlotLegends -> Placed[{"m"}, {0.1, 0.9}]]
p2 = ErrorListPlot[{{#1, #2}, ErrorBarPlots`ErrorBar @@ {#3, #4}} & @@@
val2, IntervalMarkersStyle -> Thick, PlotStyle -> Green, 
PlotLegends -> Placed[{"n"}, {0.1, 0.9}]]
p3 = ErrorListPlot[{{#1, #2}, ErrorBarPlots`ErrorBar @@ {#3, #4}} & @@@
val3, IntervalMarkersStyle -> Thick, PlotStyle -> Black, 
PlotLegends -> Placed[{"s"}, {0.1, 0.9}]]



list1 = {{0.12, 0}, {0.12, 10}, {0.12, 50}};

pn = ListLinePlot[list1, PlotStyle -> Dashed];

Show[{p1, p2, p3, pn}, Frame -> True, 
FrameTicks -> {{None, None}, {Automatic, Automatic}}]
$\endgroup$
0

2 Answers 2

7
$\begingroup$

It is easier to do everything in one plot and to define some helper function and to use "Epilog". E.g.:

Needs["ErrorBarPlots`"];
bar = {{#[[1]], #[[2]]}, ErrorBarPlots`ErrorBar @@ {#[[3]], #[[4]]}} &;
ErrorListPlot[{bar /@ val1, bar /@ val2, bar /@ val3}, 
 IntervalMarkersStyle -> Thick, PlotStyle -> {Red, Green, Black}, 
 PlotLegends -> {Placed[{"m", "n", "s"}, {0.1, 0.8}]}, 
 Epilog -> {Dashed, Line[{{0.12, 0}, {0.12, 50}}]}]

enter image description here

P.S. The error you observed was due to the plot range. MMA takes the first it meets and this excluded the third entry.

$\endgroup$
10
$\begingroup$

The ErrorBar functionality has been superseded by Around and VectorAround objects. Sample usage is presented below.

Clear[v1, v2, v3]
v1 = VectorAround[{0.12, 10}, {0.01, 1}];
v2 = VectorAround[{0.12, 20}, {0.01, 2}];
v3 = VectorAround[{0.12, 30}, {0.01, 3}];

ListPlot[List /@ {v1, v2, v3}
 , PlotStyle -> {Red, Green, Blue}
 , PlotRange -> {{0, 0.2}, {0, 35}}
 , PlotLegends -> Placed[LineLegend[
    {Red, Green, Blue}, {"m", "n", "s"}
    , LegendLayout -> "ReversedColumn"]
   , {0.9, 0.5}
   ]
 ]

enter image description here

$\endgroup$
2
  • $\begingroup$ Dear @Daniel Huber I wanted to thank you for helping. you solved my problem $\endgroup$
    – asal
    Jan 8 at 12:31
  • 1
    $\begingroup$ Dear @Syed, I sincerely appreciate your help $\endgroup$
    – asal
    Jan 8 at 12:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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