Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
386 views
in Technique[技术] by (71.8m points)

wolfram mathematica - Saving plot annotations

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

top-answerers

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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 inert Head like AddedAnnotation or some such, then you could find all these edits programmatically via

Cases[editedPic, _AddedAnnotation, Infinity]

As it is, I find myself digging through the InputForm of the image and I'm not certain that your Rest[pic[[1, 1]]] is always going to work, particularly in future versions.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...