4
$\begingroup$

I want the the dots replaced by crosses in the following plot

Plot[Sin[x],{x,0,6.5},PlotStyle ->{Blue,Dotted}] 

Could anyone help please?

$\endgroup$
  • $\begingroup$ ListPlot[Table[Sin[x], {x, 0, 6.5, 0.25}], PlotMarkers -> "+" ] $\endgroup$ – LouisB Mar 11 '17 at 6:16
  • $\begingroup$ Related: (8454) $\endgroup$ – Mr.Wizard Mar 11 '17 at 7:32
  • $\begingroup$ Hi Jee, have you figured out how to accept answers yet? $\endgroup$ – Michael E2 Mar 12 '17 at 22:30
8
$\begingroup$

Using MeshFunctions->{"ArcLength"} to get equally spaced mesh points and post-processing Points to "\[Cross]"s:

Plot[Sin[x], {x, -2 Pi, 2 Pi}, PlotStyle -> None, Mesh -> 60,
  MeshFunctions -> {"ArcLength"}, MeshStyle -> Blue] /. 
 Point[x_] :> (Text[Style["\[Cross]", 12], #] & /@ x)

Mathematica graphics

Notes:

As noted by @Mr.Wizard in the comments, to get equal arclengths we need to use AspectRatio->Automatic:

Plot[Sin[x], {x, -2 Pi, 2 Pi}, PlotStyle -> None, Mesh -> 60, 
  AspectRatio -> Automatic, MeshFunctions -> {"ArcLength"}, 
  MeshStyle -> Blue, PlotRangePadding -> .2, ImageSize -> 500] /. 
 Point[x_] :> (Text[Style["\[Cross]", 12], #] & /@ x)

Mathematica graphics

Also, as noted in Point Renderings Slightly Off in Mathematica

Precise positioning is not really achievable when glyphs from a font are used as plot markers

This issue can be dealt with using the third argument of Text, e.g., Text[Style["\[Cross]", 30], #, Scaled[{.5, .46}]] as suggested by @Mr.Wizard in the comments (see also this answer by Mr.W). Alternatively, we can make a graphics version of \[Cross]

cross = First[First[ImportString[ExportString[ Style["\[Cross]", Italic,
    FontSize -> 24, FontFamily -> "Times"], "PDF"], "PDF", "TextMode" -> "Outlines"]]]

and use Inset[Graphics[{Blue, cross}, ImageSize -> 8], #] & instead of Text[Style["\[Cross]", 12], #] & above.

| improve this answer | |
$\endgroup$
  • $\begingroup$ Nice! But it's not evenly spaced without AspectRatio -> Automatic. $\endgroup$ – Mr.Wizard Mar 11 '17 at 7:31
  • $\begingroup$ @Mr.Wizard, good point, thank you. $\endgroup$ – kglr Mar 11 '17 at 7:32
  • $\begingroup$ Also why not Mesh -> 100 ? $\endgroup$ – Mr.Wizard Mar 11 '17 at 7:35
  • $\begingroup$ @Mr.Wizard, of course!! Thank you again. $\endgroup$ – kglr Mar 11 '17 at 7:43
  • 1
    $\begingroup$ You can get even spacing with other aspect ratios using ScalingFunctions like I did here. $\endgroup$ – Michael E2 Mar 11 '17 at 14:20

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.