Errorbars using ListPlot and Epilog
- To: mathgroup at smc.vnet.net
- Subject: [mg43977] Errorbars using ListPlot and Epilog
- From: "Philip M. Howe" <pmhowe at lanl.gov>
- Date: Thu, 16 Oct 2003 04:16:12 -0400 (EDT)
- Sender: owner-wri-mathgroup at wolfram.com
I want to make some plots showing error bars. There are several
MathGroup threads showing how MultipleListPlot can be used to show
error bars. However, I find that MultipleListPlot doesn't offer me
the flexibility I seek. For example, PointSize doesn't seem to be an
option, and I don't particluarly like their symbols. I have
therefore written a snippet that allows me to use ListPlot and Epilog
to add the error bars. The snippet is;
Needs["Graphics`Colors`"];
errorListPlot[data_, xplus_, xminus_, yplus_, yminus_] :=
Module[{xerrorPlus, xerrorMinus, xerror, myErrorX, yerrorPlus,
yerrorMinus, yerror, myErrorY},
xerrorPlus =
Transpose[{Transpose[data][[1]] + xplus, Transpose[data][[2]]}];
xerrorMinus =
Transpose[{Transpose[data][[1]] - xminus, Transpose[data][[2]]}];
xerror = Table[{Part[
xerrorPlus, n], Part[xerrorMinus, n]}, {n, 1, Length[data]}];
myErrorX = Map[Line, Transpose[{xerrorPlus, xerrorMinus}]];
yerrorPlus =
Transpose[{Transpose[data][[1]], Transpose[data][[2]] + yplus}];
yerrorMinus =
Transpose[{Transpose[data][[1]], Transpose[data][[2]] - yminus}];
yerror = Table[{Part[
yerrorPlus, n], Part[yerrorMinus, n]}, {n, 1, Length[data]}];
myErrorY = Map[Line, Transpose[{yerrorPlus, yerrorMinus}]];
ListPlot[data, PlotStyle -> PointSize[.02], Frame -> True,
Background -> Linen, Epilog -> {myErrorX, myErrorY}]];
This works OK. Try the following:
mydata = Table[{x, Sin[x]}, {x, 0., 3, 0.5}];
errorListPlot[mydata, .05, .05, .1, .1];
It has (at least) two shortcomings that I haven't sorted out: 1. I
would like the option of having different errors at the various
points - i.e., I ought to be able to introduce an error list for the
x and y errors, and 2. Many journals prefer that the error bars have
small lines that terminate the error bar - i.e, the error bar ends up
looking like a capital "I". Also, I realize the coding style is
rather primitive, so I won't be embarrassed if you offer changes. Any
suggestions?
Thanks in advance for the help.
Phil
--
Philip M. Howe
Program Manager, Stockpile Surety
Los Alamos National Laboratory
(505) 665-5332
(505) 667-9498
Fax: 505-665-5249
email pmhowe at lanl.gov
Mail Stop P945