Mathematica Stack Exchange is a question and answer site for users of Mathematica. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Is it possible to create an interactive plot that has drag-down / across horizontal & vertical guides a la Illustrator / InDesign?

I would like to generate something like this:

enter image description here

I would ideally like to drag multiple (unlimited?) horizontal and vertical guide lines, which would then stay in the positions that they are left in.

In addition (if it is not asking too much!) I would really like the guidelines to 'snap' to integers as well.

I have looked at various locator manipulations, with no success. Apologies for not including my Mathematica coding effort, but I don't really know where to start with this one :/

share|improve this question
LocatorPane allows you to interactively add or remove Locators. – Sjoerd C. de Vries Nov 20 '13 at 10:59
up vote 4 down vote accepted

Cheap and cheerful:

  {Round[xguide, 2],
    {x, 0, 200}, 
    PlotPoints -> 200,
    ImageSize -> 600,
    Epilog -> {Gray,
      Line[{{Round[xguide[[1]], 2], -1000}, {Round[xguide[[1]], 2], 
      Line[{{-1000, Round[ xguide[[2]], 2]}, {1000, 
         Round[xguide[[2]], 2]}}]
 {{xguide, {20, 20}}, Locator, Appearance -> None}]


I'll leave you to explore the unlimited guides option... :)

share|improve this answer
@ Cormullion, great! thanks - gets me part way there ;) – martin Nov 20 '13 at 10:46
Added 1/2 to Round[xguide[[2]] + 0.5, 1] & seems to 'snap' to plot points ok now :) – martin Nov 20 '13 at 11:05
The rounding to 2 was only to make you notice Round. :) I had thought of decreasing the rounding strength as it approached the plotted line, but I got distracted... – cormullion Nov 20 '13 at 13:39

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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