Yesterday, while adding some timing plots to the "Optimally picking one element from each list" question I was once more remembered of a mathgroup posting I did a couple of years ago ("Keeping plot annotations after regenerating a plot").
I was happily annotating my plots (manually) when I thought that some axis labels would be nice. Problem is, regenerating the plots with the axis labels in place will destroy your manual annotations.
It appears you can find user additions in a plot named pic here: Rest[pic[[1, 1]]]
, so if you regenerate the plot as pic2 you can get your annotations back if you use:
Insert[pic2, Rest[pic[[1, 1]]], {1, 1}]
I remember David Park (author of the Presentations package) being vehemently opposed to manual annotations. I have done quite some programmatic labeling myself, but sometimes placing labels under program control is just too difficult, like here (note that I don't like PlotLegends
much, especially because some of the colors are close to each other):
It was already too late for my kludge, having thrown away the plot originals, but I wonder what the current state of thinking on this issue is.
- Are there better ways to do this?
- How general is this method? Does it work in all plot and chart types?
- Does it work in all versions? (above 5.2)
- Any WRI plans to improve handling of user additions in plots?
BTW The trick in my mathgroup posting differed slightly from the one shown above and used in the top-10 plot. The principle is the same, though.
EDIT
I placed the code to make SO data plots like the one above in the Mathematica Toolbag.
EDIT
The code is now moved to the more appropriate question by Brett Champion: How do I access the StackOverflow API from Mathematica
One method, which is a bit ugly but seems to work reasonably OK for minor plot annotations, is the following.
After adding annotations via the
Drawings tools
, the additional info is stored with the graphic and may be inspected by, for example, selecting the graphic bracket and usingShow Expression
(Shift-Command-E on a Mac). The additional information can usually be picked out by cut-and-paste or usingCases
, and then may be added to the new modified plot usingEpilog
.For example
Adding a few annotations gives the following:
Assigning the name
plotgraphic
to the above image, a new modified plot with added annotations present may be generated as follows (for example)giving
This can be awkward, to say the least, and the method no doubt can be improved. It is also probably along the lines of what others already do. Nevertheless, it goes give a plot where the annotations are present 'programmatically', and as no-one has mentioned
Epilog
, I decided it might be worth posting.Personally, I agree with David Park that programmatic addition of annotation is superior. It's also likely to be more robust and work with future editions of Mathematica. I'd really like to see the drawing tools palette improved a bit and I'd like to see multiple annotations added by hand appear in the resulting
Graphics
object more clearly. If there were an inertHead
likeAddedAnnotation
or some such, then you could find all these edits programmatically viaAs it is, I find myself digging through the
InputForm
of the image and I'm not certain that yourRest[pic[[1, 1]]]
is always going to work, particularly in future versions.