Advertisement
Guest User

FilledErrorPlot

a guest
Oct 14th, 2012
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.63 KB | None | 0 0
  1. FilledErrorPlot::usage = "FilledErrorPlot takes data and computes filled error plots";
  2.  
  3. FilledColor::usage = "FilledColor is an option for FilledErrorPlot";
  4. ErrorOnMean::usage = "ErrorOnMean is an option for FilledErrorPlot. If set to False it will display\
  5. the error in the PDF";
  6. ThreeSigma::usage = "ThreeSigma is an option for FilledErrorPlot. If set to True it will display t\
  7. he 3sigma error";
  8. DisplayMean::usage = "DisplayMean is an option for FilledErrorPlot. If set to False it will not dis\
  9. play the mean of the PDF";
  10. DisplayError::usage = "DisplayMean is an option for FilledErrorPlot. If set to False it will not di\
  11. splay the error of the PDF";
  12. NonParametric::usage = "NonParametric is an option for FilledErrorPlot. If set to True it will use \
  13. median and median deviation.";
  14. FilledErrorPlot::usage = "FilledErrorPlot[dat] Plots a Filled Plot of the average of data";
  15.  
  16. Clear[FilledErrorPlot];
  17. Options[FilledErrorPlot] =
  18. Flatten[{ErrorOnMean -> True, DisplayMean -> True,
  19. DisplayError -> True, NonParametric -> False,
  20. FilledColor -> Pink, DataRange -> Automatic,
  21. Options[ListLinePlot], ThreeSigma -> False}];
  22.  
  23. FilledErrorPlot[dat_, opts : OptionsPattern[]] :=
  24. Module[{opt = Sequence @@ FilterRules[{opts}, Options[ListLinePlot]],
  25. mean, rg, sig, mm, std, norm, col},
  26. col = OptionValue[FilledColor];
  27. std = If[OptionValue[NonParametric], MedianDeviation,
  28. StandardDeviation];
  29. If[Length[Dimensions[dat]] == 2,
  30. rg = OptionValue[DataRange];
  31. If[rg == Automatic, rg = Range[Dimensions[dat] // Last]];
  32. mm = If[OptionValue[NonParametric], Median, Mean];
  33. mean = Map[mm, Transpose[dat]]; sig = Map[std, Transpose[dat]];
  34. norm = If[OptionValue[ErrorOnMean], dat // Dimensions // First, 1];,
  35. mm = If[OptionValue[NonParametric], Median, Mean];
  36. mean = Map[mm, Transpose[dat /. {x_, y_Real} -> y]];
  37. rg = dat /. {x_, y_Real} -> x // First;
  38. sig = Map[std, Transpose[dat /. {x_, y_Real} -> y]];
  39. If[OptionValue[ThreeSigma], sig *= 3];
  40. norm =
  41. If[OptionValue[ErrorOnMean], dat // Dimensions // First, 1];
  42. ];
  43. {If[OptionValue[DisplayError],
  44. ListLinePlot[{Transpose[{rg, mean - sig/Sqrt[norm]}],
  45. Transpose[{rg, mean + sig/Sqrt[norm]}]},
  46. Filling -> {1 -> {2}},
  47. PlotStyle -> Lighter /@ {col, col},
  48. FillingStyle -> Opacity[0.2, Lighter[col]],
  49. opt], {}],
  50. If[OptionValue[DisplayMean],
  51. ListLinePlot[Transpose[{rg, mean}], PlotStyle -> col,
  52. opt], {}]} // Show]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement