Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- FilledErrorPlot::usage = "FilledErrorPlot takes data and computes filled error plots";
- FilledColor::usage = "FilledColor is an option for FilledErrorPlot";
- ErrorOnMean::usage = "ErrorOnMean is an option for FilledErrorPlot. If set to False it will display\
- the error in the PDF";
- ThreeSigma::usage = "ThreeSigma is an option for FilledErrorPlot. If set to True it will display t\
- he 3sigma error";
- DisplayMean::usage = "DisplayMean is an option for FilledErrorPlot. If set to False it will not dis\
- play the mean of the PDF";
- DisplayError::usage = "DisplayMean is an option for FilledErrorPlot. If set to False it will not di\
- splay the error of the PDF";
- NonParametric::usage = "NonParametric is an option for FilledErrorPlot. If set to True it will use \
- median and median deviation.";
- FilledErrorPlot::usage = "FilledErrorPlot[dat] Plots a Filled Plot of the average of data";
- Clear[FilledErrorPlot];
- Options[FilledErrorPlot] =
- Flatten[{ErrorOnMean -> True, DisplayMean -> True,
- DisplayError -> True, NonParametric -> False,
- FilledColor -> Pink, DataRange -> Automatic,
- Options[ListLinePlot], ThreeSigma -> False}];
- FilledErrorPlot[dat_, opts : OptionsPattern[]] :=
- Module[{opt = Sequence @@ FilterRules[{opts}, Options[ListLinePlot]],
- mean, rg, sig, mm, std, norm, col},
- col = OptionValue[FilledColor];
- std = If[OptionValue[NonParametric], MedianDeviation,
- StandardDeviation];
- If[Length[Dimensions[dat]] == 2,
- rg = OptionValue[DataRange];
- If[rg == Automatic, rg = Range[Dimensions[dat] // Last]];
- mm = If[OptionValue[NonParametric], Median, Mean];
- mean = Map[mm, Transpose[dat]]; sig = Map[std, Transpose[dat]];
- norm = If[OptionValue[ErrorOnMean], dat // Dimensions // First, 1];,
- mm = If[OptionValue[NonParametric], Median, Mean];
- mean = Map[mm, Transpose[dat /. {x_, y_Real} -> y]];
- rg = dat /. {x_, y_Real} -> x // First;
- sig = Map[std, Transpose[dat /. {x_, y_Real} -> y]];
- If[OptionValue[ThreeSigma], sig *= 3];
- norm =
- If[OptionValue[ErrorOnMean], dat // Dimensions // First, 1];
- ];
- {If[OptionValue[DisplayError],
- ListLinePlot[{Transpose[{rg, mean - sig/Sqrt[norm]}],
- Transpose[{rg, mean + sig/Sqrt[norm]}]},
- Filling -> {1 -> {2}},
- PlotStyle -> Lighter /@ {col, col},
- FillingStyle -> Opacity[0.2, Lighter[col]],
- opt], {}],
- If[OptionValue[DisplayMean],
- ListLinePlot[Transpose[{rg, mean}], PlotStyle -> col,
- opt], {}]} // Show]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement