Mathematica Asked on May 8, 2021
I have a dataset with errors. I use "ListErrorPlot" to plot the data with the subquent errorbars. Now I need to shade the the data region. The shaded region will include data with error bars only.
Following is my code:
Needs["ErrorBarPlots`"]
data = {{0, 1, 0.17}, {5, 1.4, 0.27}, {10, 1.95, 0.23}, {15, 2.05,
0.18}, {20, 2.55, 0.21}, {25, 3.01, 0.28}, {30, 3.76, 0.11}};
ErrorListPlot[data, PlotStyle -> {Hue[0.6, 1, 1]},
PlotMarkers -> {[FilledCircle], 15}, Frame -> True,
FrameStyle -> Directive[Black, Thickness[0.002]],
FrameLabel -> {Style["x", Black, FontFamily -> "Arial",
FontSize -> 20],
Style["y", Black, FontFamily -> "Arial", FontSize -> 20]},
PlotRange -> {{-2, 32}, {0.8, 4.1}}, FrameTicks -> Automatic,
ImageSize -> 400,
BaseStyle -> {FontFamily -> "Times", FontSize -> 15}]
How can I do it? Please help me to get rid of this.
Thank you.
Perhaps this is what you want
Needs["ErrorBarPlots`"] // Quiet
data = {{0, 1, 0.17}, {5, 1.4, 0.27}, {10, 1.95, 0.23}, {15, 2.05,
0.18}, {20, 2.55, 0.21}, {25, 3.01, 0.28}, {30, 3.76, 0.11}};
Show[
ErrorListPlot[data, PlotStyle -> {Hue[0.6, 1, 1]},
PlotMarkers -> {●, 15}, Frame -> True,
FrameStyle -> Directive[Black, Thickness[0.002]],
FrameLabel -> {Style["x", Black, FontFamily -> "Arial",
FontSize -> 20],
Style["y", Black, FontFamily -> "Arial", FontSize -> 20]},
PlotRange -> {{-2, 32}, {0.8, 4.1}}, FrameTicks -> Automatic,
ImageSize -> 400,
BaseStyle -> {FontFamily -> "Times", FontSize -> 15}],
ListLinePlot[{{#[[1]], Total@Rest@#} & /@
data, {#[[1]], Subtract @@ Rest@#} & /@ data},
Filling -> {1 -> {2}}, PlotStyle -> None]]
EDIT: Use Filling -> {1 -> {{2}, LightRed}
, reverse the order of the plots, and move the graphics options into the Show
, e.g.,
Show[
ListLinePlot[{
{#[[1]], Total@Rest@#} & /@ data,
{#[[1]], Subtract @@ Rest@#} & /@ data},
Filling -> {1 -> {{2}, LightRed}},
PlotStyle -> None],
ErrorListPlot[data,
PlotStyle -> {Hue[0.6, 1, 1]},
PlotMarkers -> {●, 15}],
Frame -> True,
FrameStyle -> Directive[Black, Thickness[0.002]],
FrameLabel ->
(Style[#, Black, FontFamily -> "Arial", FontSize -> 20] & /@ {"x", "y"}),
PlotRange -> {{-2, 32}, {0.8, 4.1}},
FrameTicks -> Automatic,
ImageSize -> 400,
BaseStyle -> {FontFamily -> "Times", FontSize -> 15}]
Alternatively, use FillingStyle -> LightRed
in the revised Show
.
Answered by Bob Hanlon on May 8, 2021
If you have version 12.0+, you can also (1) use Around
to pre-process input data, and (2) use ListPlot
with options IntervalMarkers
and IntervalMarkersStyle
:
data2 = {#, Around[#2, #3]} & @@@ data;
ListLinePlot[{data2, data2}, IntervalMarkers -> { "Fences", "Bands"},
IntervalMarkersStyle -> {Red, Directive[LineOpacity -> 0, Orange]},
PlotStyle -> Red, PlotMarkers -> {"●", 10},
Frame -> True,
FrameLabel -> {Style["x", Black, FontFamily -> "Arial", FontSize -> 20],
Style["y", Black, FontFamily -> "Arial", FontSize -> 20]},
PlotRange -> {{-2, 32}, {0.8, 4.1}}, FrameTicks -> Automatic,
ImageSize -> 400,
BaseStyle -> {FontFamily -> "Times", FontSize -> 15}]
Answered by kglr on May 8, 2021
Get help from others!
Recent Questions
Recent Answers
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP