9
$\begingroup$

I would like to use ListPlot to plot some points. I would like the PlotMarkers to be open circles. I can use PlotMarkers -> Graphics[Circle[]], as in the following example, but the circles are too large. Is there a way that I can specify the size of open circles to use in PlotMarkers? Thanks for your time.

myData = {{0, 3.0}, {10, 3.1}, {20, 3.2}, {30, 3.0}, {40, 3.0}, {90, 3.0}};

ListPlot[myData, PlotRange -> {{-1, 101}, {2.9, 3.3}}, Joined -> True,
  Mesh -> Full, Frame -> True, PlotStyle -> Directive[Red, Thick], 
  PlotMarkers -> Graphics[{Red, Thick, Circle[]}]]

PlotMarkers

$\endgroup$
2

6 Answers 6

14
$\begingroup$

PlotMarkers are rendered as insets to the graphics so you need to set a small image size in your graphics plot marker:

ListPlot[myData, PlotRange -> {{-1, 101}, {2.9, 3.3}}, Joined -> True,
  Mesh -> Full, Frame -> True, PlotStyle -> Directive[Red, Thick], 
 PlotMarkers -> Graphics[{Red, Thick, Circle[]}, ImageSize -> 10]]

enter image description here

Because plot markers are insets you may find that if you have a large number of points the graphic rendering is noticeably slow -- particular if the plot is made dynamic. In that case you can try and use primitives directly to get some speed improvements. This example hasn't quite worked out as planned because I've made an elipse rather than a circle for reasons not immediately clear (but probably obvious to someone else who might like to point out the error).

ListLinePlot[myData, PlotRange -> {{-1, 101}, {2.9, 3.3}}, 
 Frame -> True, PlotStyle -> Directive[Red, Thick], 
 Epilog -> {Red, Thick, Circle[#, Scaled[.01]] & /@ myData}]

enter image description here

Edit

it appears that AspectRatio is messing up the scaling but this can be fixed:

ListLinePlot[myData, PlotRange -> {{-1, 101}, {2.9, 3.3}}, 
 Frame -> True, PlotStyle -> Directive[Red, Thick], 
 Epilog -> {Red, Thick, 
   Disk[#, Scaled[{0.02, 0.02*GoldenRatio}]] & /@ myData}]

enter image description here

...some random shapes:

ListLinePlot[myData, PlotRange -> {{-1, 101}, {2.9, 3.3}}, 
 Frame -> True, PlotStyle -> Directive[Red, Thick], 
 Epilog -> {Red, Thick, 
   Polygon[{Scaled[{0.003, 0.01}, #], Scaled[{-0.03, 0.03}, #], 
       Scaled[{-0.03, -0.03}, #], Scaled[{0.02, -0.05}, #]}] & /@ 
    myData}]

enter image description here

...with the qualifier that you would go down this path if you have a large data set and plot markers (insets) are slowing things down.

$\endgroup$
5
$\begingroup$

I repeatedly recommend using graphics primitives for the sake of performance, and in many cases simplicity or at least predictability. I therefore support Mike's use of Epilog. There is however a simpler method to render circles rather than ellipses: Offset. This also produces a fixed-size "point" which may or may not be desired.

myData = {{0, 3.0}, {10, 3.1}, {20, 3.2}, {30, 3.0}, {40, 3.0}, {90, 3.0}};

ListLinePlot[myData,
 PlotRange -> {{-1, 101}, {2.9, 3.3}},
 Frame -> True, PlotStyle -> Directive[Red, Thick],
 Epilog -> {Red, Thick, Circle[#, Offset @ 5] & /@ myData}
]

enter image description here

Offset also works within PlotMarkers if you prefer to use the canonical method:

PlotMarkers -> Graphics[{Red, Thick, Circle[{0, 0}, Offset @ 5]}]
$\endgroup$
4
$\begingroup$

What about the "Empty Circle" in the special characters menu. Go to Insert_Special Characters_Symbols to find it or type esc_eci_esc.

$\endgroup$
2
  • 2
    $\begingroup$ Font based markers have alignment issues $\endgroup$
    – rm -rf
    Commented Feb 28, 2013 at 0:22
  • $\begingroup$ I agree with Nguyen - the best solution is to simply use: PlotMarkers -> "[EmptyCircle]" ... [EmptyCircle] with a backslash before ... site is dropping the backslash ... Works like a charm. Even better, you can adjust the size of the circle by simply selecting it with the mouse, and changing the font size. Same goes for changing the colour: just select the circle and change the colour to something that suits you. The end result is the neatest and shortest code. $\endgroup$
    – wolfies
    Commented Apr 9, 2013 at 9:23
3
$\begingroup$

I can't comment, so I'd just like to expand on the difference between Mike Honeychurch's and Nguyen Van Falk's answers. Using graphics (like Mike) is slow if you have many points on the graph. This is a reason to use mere characters (like Nguyen). However, as veteran "rm -rf" pointed out in the comments to Nguyen's post, there can be some minor alignment issues due to the way fonts are rendered which are not very easy to fix in an a robust way.

Therefore, the best idea is to use characters when you need to plot quickly, and use slow graphics when you need something beautiful. To choose a character, bring up the Special Characters panel from the Palette menu.

$\endgroup$
2
$\begingroup$

Often PlotMarkers may not align exactly the way you expect. An alternate to ListPlot is to construct the plot using Graphics primitives.

    myData = {{0, 3.0}, {10, 3.1}, {20, 3.2}, {30, 3.0}, {40, 3.0}, {90, 
        3.0}};

    Manipulate[
     Graphics[{{Blue, Line[myData]},
       {Red, GeometricTransformation[Circle[{0, 0}, Offset[{size, size}]],
          myData]}},
      PlotRange -> {{-1, 101}, {2.9, 3.3}}, Frame -> True, 
      PlotRangeClipping -> True, AspectRatio -> 1],
     {size, 5, 15}]

I first saw GeometricTransformation used for this purpose as an answer to a question on this site, but I can't seem to locate it now.

$\endgroup$
1
$\begingroup$

The problem with malaligned PlotMarkers doesn't exist anymore. Here we use them with a size of 26 and see, that they nicely align with the red mesh points.

How to input EmptyCircle

Shapes and Icons

list =
  {{0, 3.0}, {10, 3.1}, {20, 3.2}, {30, 3.0}, {40, 3.0}, {90, 3.0}};

ListPlot[list,
 PlotRange -> {{-10, 101}, {2.9, 3.3}},
 Joined -> True,
 Mesh -> Full,
 Frame -> True,
 GridLines -> Automatic,
 PlotRangePadding -> Automatic,
 PlotStyle -> Directive[Red, Thick],
 PlotMarkers -> Style["\[EmptyCircle]", 26, Blue]]

enter image description here

$\endgroup$
4
  • $\begingroup$ Is it possible to control the thickness of the shape when using this method? $\endgroup$
    – Kvothe
    Commented Jan 31 at 18:31
  • $\begingroup$ PlotMarkers -> Style["\[EmptyCircle]", 26, Blue, Thickness[0.001]] doesn't show any effect. But you can change the size: 12 instead of 26 for example. $\endgroup$
    – eldo
    Commented Jan 31 at 18:59
  • $\begingroup$ Right but that means there is only one parameter to change (and not one for the radius and one for the thickness as would be preferable). $\endgroup$
    – Kvothe
    Commented Feb 1 at 11:48
  • $\begingroup$ The issue still exists with Mma version 13.2.1. Indeed, if we make the radius of the blue circles only slightly larger than the radius of the red bullets, we can clearly see that the two are not concentric. $\endgroup$
    – G Reissig
    Commented Feb 13 at 13:39

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.