6

What is the simplest / most convenient way to separate hand-drawn objects in Mathematica from programmatically generated ones?

The interactive drawing tools are convenient and useful. But if I draw something on top of the plot, it will get lost as soon as the plot is re-generated. Is there a convenient solution for this?

I could make the drawing on top of an empty plot, them combine them with the actual plot. But this is again inconvenient as I need to manually set the plot range of the empty plot and I don't see the background on top of which I'm adding the annotations.

Szabolcs
  • 24,728
  • 9
  • 85
  • 174
  • 5
    Related question: http://stackoverflow.com/q/5744117/421225 – Simon Oct 03 '11 at 13:53
  • @Simon you are right, perhaps someone can merge? – Szabolcs Oct 04 '11 at 08:27
  • 1
    I'm happy having them separate. [Sjoerd's question](http://stackoverflow.com/q/5744117/421225) is distracting with its cool plot, and [Brett's nice semantic answer](http://stackoverflow.com/questions/7635181/separate-hand-drawn-objects-in-mathematica/7640149#7640149) (as opposed to [TomD's syntactic answer](http://stackoverflow.com/questions/5744117/saving-plot-annotations/5753555#5753555)) deserves to be easy to find. Anyway, the two questions are "Linked" in right hand column of the page, so are easy to find from one another. – Simon Oct 04 '11 at 08:52

2 Answers2

14

One approach, using an annotation to flag the generated content:

Plot[Annotation[Sin[x], "GeneratedPrimitives"], {x, 0, 10}]

RecoverDrawing[g_Graphics] := g /. Annotation[_, "GeneratedPrimitives"] :> {}

RecoverDrawing[<modified graphic>]

enter image description here

Brett Champion
  • 8,497
  • 1
  • 27
  • 44
  • 4
    +1 Good one Brett! This answers the question I had with earlier iterations of this problem (where you had to hack around on certain positions in the Graphics structure using Part), namely will this work in future versions? Using Annotation seems to be the more robust way. – Sjoerd C. de Vries Oct 03 '11 at 20:39
0

Unfortunately, the best thing I can think of is writing a program using ClickPane or EventHandler which not only draws bu records the points being added to the image. A modification of code like:

DynamicModule[{pts = {}}, 
 ClickPane[Dynamic[Framed@Graphics[Line[pts], PlotRange -> 1]], 
  AppendTo[pts, #] &]] 
Dr. belisarius
  • 60,527
  • 15
  • 115
  • 190
Searke
  • 779
  • 3
  • 3