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 :/

  • $\begingroup$ LocatorPane allows you to interactively add or remove Locators. $\endgroup$ – Sjoerd C. de Vries Nov 20 '13 at 10:59

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... :)

| improve this answer | |
  • $\begingroup$ @ Cormullion, great! thanks - gets me part way there ;) $\endgroup$ – martin Nov 20 '13 at 10:46
  • $\begingroup$ Added 1/2 to Round[xguide[[2]] + 0.5, 1] & seems to 'snap' to plot points ok now :) $\endgroup$ – martin Nov 20 '13 at 11:05
  • 1
    $\begingroup$ 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... $\endgroup$ – cormullion Nov 20 '13 at 13:39

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.