0
$\begingroup$

How do I add a cross, (say + shape or x) as a graphic to a plot in a similar way as I would add a point using Point.

Existing solutions (https://mathematica.stackexchange.com/a/155162/45020) seem to always use a whole extra listplot. This seems cumbersome for just adding one point.

Additionally I noticed that the two lines of the cross for some reason don't cross in the middle in that answer (most noticeable if you take FontSize -> 15).

So how do I add a + or - shape to a plot, centered at the point I give it and with the obvious required symmetries regardless of the size of the marker.

I would be hoping for something of the form Show[plot,Graphics[cross[{x, y}]]] with very similar behavior to Point but instead showing a cross.

$\endgroup$
7
  • $\begingroup$ I don't understand the question. Do you want to change the plot marker in ListPlot? Or do you want to add a single cross to an arbitrary existing graphic? Also, if you know how to add a point with Point, adding a cross is exactly the same, with two Lines. Please clarify and address these. $\endgroup$
    – Szabolcs
    Commented Dec 9, 2019 at 11:54
  • $\begingroup$ I would prefer not to add a whole ListPlot and instead add a Graphics object. I could do this with two lines. But I would want to declare some function cross[xylist_] that takes only the center around which there should be a cross and not all the endpoints of the lines. Perhaps the best solution is something of this form but I would still need to do something complicated in order to find the required length of the lines so that I get an absolute size and not something that depends on the data. $\endgroup$
    – Kvothe
    Commented Dec 9, 2019 at 12:57
  • 1
    $\begingroup$ You could write a tiny function that takes a coordinate pair and construct a cross on top of it from Lines. Then you can use with with Epilog or with Show (as in your example). Offset coordinates will be useful for consistent sizing. $\endgroup$
    – Szabolcs
    Commented Dec 9, 2019 at 15:07
  • 2
    $\begingroup$ Looks like a use case for my PolygonMarker function. $\endgroup$ Commented Dec 9, 2019 at 16:19
  • 1
    $\begingroup$ Here's a cross function. The second argument is the size in printer's points. It acts like AbsolutePointSize and is independent of the figure size. cross[pos_, s_] := {Line[{Offset[{-s, 0}, pos], Offset[{s, 0}, pos]}], Line[{Offset[{0, -s}, pos], Offset[{0, s}, pos]}]} $\endgroup$
    – Szabolcs
    Commented Dec 9, 2019 at 18:29

0

Browse other questions tagged or ask your own question.