Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

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

1 Answer 1

up vote 4 down vote accepted

Cheap and cheerful:

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

rulers

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
1  
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

 
discard

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.