6
$\begingroup$

I think I found a bug in Mathematica 11.2 with ErrorListPlot. Any use of the option PlotMarkers in ErrorListPlot leads to no error bars, unless one uses Joined -> True. A similar (or the same) bug I saw reported for Mathematica 10. It seems it was corrected, but it has returned. I am running Mathematica on a Mac (macOSX).

Example:

Needs["ErrorBarPlots`"]
data = Sort[Table[{{RandomReal[10], RandomReal[10]}, ErrorBar[RandomReal[5]]}, {i, 10}]];
ErrorListPlot[data, PlotRange -> All]
ErrorListPlot[data, PlotRange -> All, PlotMarkers -> "A"]
ErrorListPlot[data, PlotRange -> All, PlotMarkers -> "A", Joined -> True]

Resulting plots

The PlotMarkers that I want are more elaborate than an "A", but this simple example illustrates the problem.

Any ideas on how I can avoid this issue? I want to specify PlotMarkers and I want the error bars, but I do not want the Joined -> True option.

Alternative packages to the ErrorBarPlots are also welcome.

$\endgroup$
2
  • 1
    $\begingroup$ In Mathematica 12.2 I do not reproduce this bug. $\endgroup$ Mar 6 at 7:00
  • 1
    $\begingroup$ In Mathematica 12.1 I also no longer reproduce this bug. $\endgroup$
    – Davi
    Mar 7 at 5:08
5
$\begingroup$

Another workaround is simply to remove the line added due to Joined -> True:

ErrorListPlot[data, PlotRange -> All, PlotMarkers -> "A", Joined -> True] /. 
 Line[pts : {{x1_?NumericQ, _}, {x2_, _}, {_, _} ...}] /; x1 != x2 -> Nothing

plot

$\endgroup$
4
$\begingroup$

It seems there is no alternative package to ErrorBarsPlot. I did a small package that implements error bars into ListPlot. It is also more "user friendly" considering the kind of plots that I need to do. On the other hand, it is less close to the ListPlot output than ErrorListPlot. This package is based on the function ELPlot defined below. This function solves the issue that I raised in the question above. The package I will post on a webpage soon. Any comments are welcome.

disk[color_, size_: 10, thickness_: 1] :=  Graphics[{color, AbsoluteThickness[thickness], Disk[]}, ImageSize -> size]

Options[ELPlot] = {
MarkersColor -> Black,
LinesColor -> Black,
MarkersSize -> 10,
MarkersThickness -> 1,
LinesThickness -> 1.2,
Markers -> disk,
LinesHorizontalLength -> 0.01
};

ELPlot[data_?ListQ, error_?ListQ, opts : OptionsPattern[{ELPlot, ListPlot}]] := 
Block[{dt = data, er = error, dataerrorpos, horizontallength, 
verticallines, horizontallines, 
mcolor = OptionValue[MarkersColor], 
lcolor = OptionValue[LinesColor], 
linesthickness = OptionValue[LinesThickness], 
markersthickness = OptionValue[MarkersThickness], 
markersize = OptionValue[MarkersSize], 
markers = OptionValue[Markers], 
k = OptionValue[LinesHorizontalLength], SavedOptionsLinTicks, 
SavedOptionsListPlot, LPopts},

If [Length[Dimensions[er]] == 1, er = Transpose[{er, er}]]; 

dataerrorpos = Flatten[{{dt[[#, 1]], dt[[#, 2]] + er[[#, 1]]}, {dt[[#, 1]], dt[[#, 2]] - er[[#, 2]]}} & /@ Range[Length[dt]], 1];
horizontallength = (Last[#] - First[#]) &[Sort[dt[[All, 1]]]];
horizontallines = Sequence @@ (Line[{{dataerrorpos[[#, 1]] - k horizontallength, dataerrorpos[[#, 2]]}, {dataerrorpos[[#, 1]] + k horizontallength, dataerrorpos[[#, 2]]}}] & /@ Range[Length[dataerrorpos]]);
verticallines = Sequence @@ (Line[{dataerrorpos[[#]], dataerrorpos[[# + 1]]}] & /@ Range[1, Length[dataerrorpos], 2]);
LPopts = FilterRules[{opts}, Options[ListPlot]];
Show[ListPlot[dt, LPopts, PlotMarkers -> {markers[mcolor, markersize, markersthickness] }], Graphics[{AbsoluteThickness[linesthickness], lcolor, verticallines}], ListPlot[dt, LPopts, PlotMarkers -> markers[mcolor, markersize, markersthickness] }], Graphics[{AbsoluteThickness[linesthickness], lcolor, horizontallines}]]
];

Here are screenshots: enter image description here enter image description here

$\endgroup$
1
$\begingroup$

As a workaround use Text to replace the Point

Needs["ErrorBarPlots`"]
data = Sort[
   Table[{{RandomReal[10], RandomReal[10]}, ErrorBar[RandomReal[5]]}, {i, 
     10}]];

ErrorListPlot[data, PlotRange -> All] /.
 Point[pts_List] :> (Text[Style["A", 14, Bold, Red], #] & /@ pts)

enter image description here

$\endgroup$
3
  • $\begingroup$ Thanks! Indeed it solves the issue with the "A" or any text. On the other hand, if one wants to insert Graphics instead of Text, how should one adapt your workaround? I naively tried ErrorListPlot[data, PlotRange -> All] /. Point[pts_List] :> ( Graphics[Circle[#, 0.2]] & /@ pts) $\endgroup$
    – Davi
    Nov 5 '17 at 21:00
  • $\begingroup$ @DaviC.Rodrigues - Graphics is not a Graphics primitive. Just use the Circle[#, 0.2] (Graphics primitive) without the Graphics. $\endgroup$
    – Bob Hanlon
    Nov 5 '17 at 21:15
  • $\begingroup$ Great, indeed it works, it is a nice workaround! It is a pity that we need to use a workaround... $\endgroup$
    – Davi
    Nov 5 '17 at 21:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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