4
$\begingroup$

ErrorListPlot usually does not put the error bar exactly in the center of the plot markers. For example:

Needs["ErrorBarPlots`"]

data=RandomReal[{-1,1},{4,3,3}];
size=20;
{pm1,pm2,pm3,pm0}={{"\[EmptyUpTriangle]",size},{"\[EmptySquare]",1.1*size},{"\[EmptyCircle]",0.9*size},{"\[EmptyDownTriangle]",size}};
ErrorListPlot[data,PlotMarkers->{pm1,pm2,pm3,pm0}]

The output will be enter image description here

As the figure shows, bar usually lays a little right from the center of the plot marker.

Another similar question is that the text will not be in the center of a circle when they are plated at the same coordinate, for example:

Graphics[{Circle[{0, 0}, 0.01], Text[Style[17, FontSize -> 50], {0, 0}]}, ImageSize -> 67]

enter image description here

Is there anyone could solve the "typesetting problem" mentioned above elegantly?

$\endgroup$
1

2 Answers 2

9
$\begingroup$

Define the markers as shown below

marker[1] = 
Graphics[{EdgeForm[{Thickness[0.1], Blue}], FaceForm[], 
Polygon[{{0, 2}, {Sqrt[3], -1}, {-Sqrt[3], -1}}]}, ImageSize -> 10];
marker[2] = 
Graphics[{EdgeForm[{Thickness[0.13], Orange}], FaceForm[], 
Rectangle[{0, 0}]}, ImageSize -> 10];
marker[3] = 
Graphics[{EdgeForm[{Thickness[0.1], Green}], FaceForm[], 
Circle[{0, 0}, 0.1]}, ImageSize -> 10];
marker[4] = 
Graphics[{EdgeForm[{Thickness[0.1], Red}], FaceForm[], 
Polygon[{{0, -2}, {Sqrt[3], 1}, {-Sqrt[3], 1}}]}, ImageSize -> 10];
aLLmarker = Table[marker[i], {i, 1, 4}];

Now all the markers are centered properly.

 plot = ErrorListPlot[data, PlotMarkers -> aLLmarker, PlotRange -> All,
 Method -> {"OptimizePlotMarkers" -> False}, ImageSize -> 400]

 Export["2.jpg", plot, ImageResolution -> 600]

enter image description here

Note: While exporting I find that your original code works fine. I mean even though mma shows the markers to be off-centered, the final exported image is rendered properly.

You can use Offset for the last part

Graphics[{Circle[Offset[{2, 2}, {0, 0}], 0.01], 
Text[Style[17, FontSize -> 50], {0, 0}]}, ImageSize -> 67]

enter image description here

$\endgroup$
5
  • $\begingroup$ Note that all your triangle plot markers are placed incorrectly: your code assumes the "center" of upper triangle to be at 1/2 of its height while actually it is located at 1/3 of the height (the center of circumcircle), see details here. $\endgroup$ Commented Dec 3, 2015 at 7:31
  • $\begingroup$ Do you mean I should have used Polygon[{{0, 2}, {Sqrt[3], -1}, {-Sqrt[3], -1}}] and Polygon[{{0, -2}, {Sqrt[3], 1}, {-Sqrt[3], 1}}] for the up and down triangles. $\endgroup$
    – Hubble07
    Commented Dec 3, 2015 at 10:03
  • $\begingroup$ Yes, it is the best method. An alternative is to specify the explicit AlignmentPoint as Mr.Wizard done in this answer for his triangle shape. $\endgroup$ Commented Dec 3, 2015 at 10:43
  • $\begingroup$ Hi, Offset method does not solve the second question perfectly, for example,Graphics[{Circle[Offset[{2, 2}, {0, 0}], 0.01], Text[Style[2, FontSize -> 50], {0, 0}]}, ImageSize -> 50]. $\endgroup$ Commented Dec 9, 2015 at 13:29
  • $\begingroup$ you are supposed to play around with the co-ordinates. Try Graphics[{Circle[Offset[{0.5, 0.5}, {0, 0}], 0.01], Text[Style[2, FontSize -> 50], {0, 0}]}, ImageSize -> 50]. Also for some numbers it looks like we don't need any offset. Check Table[Graphics[{Circle[{0, 0}, 0.01], Text[Style[i, FontSize -> 50], {0, 0}]}, ImageSize -> 50], {i, 1, 9}]. 2 looks okay to me in the last result. $\endgroup$
    – Hubble07
    Commented Dec 9, 2015 at 13:51
2
$\begingroup$

Here is a bit of a hack to "nudge" the font-based markers.

size = 20;
{pm1, pm2, pm3, 
   pm0} = {{Framed["\[EmptyUpTriangle]", FrameStyle -> None, 
     FrameMargins -> {{1.46, 0}, {0, 0}}], size},
   {Framed["\[EmptySquare]", FrameStyle -> None, 
     FrameMargins -> {{1.46, 0}, {0, 0}}], 1.1 size},
   {Framed["\[EmptyCircle]", FrameStyle -> None, 
     FrameMargins -> {{1.46, 0}, {0, 0}}], .9 size},
   {Framed["\[EmptyDownTriangle]", FrameStyle -> None, 
     FrameMargins -> {{1.46, 0}, {0, 0}}], size}};
ErrorListPlot[data, PlotMarkers -> {pm1, pm2, pm3, pm0}]

Using graphics primitives is preferable, but in case you need some special glyphs this could be useful.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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