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.
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
Sometimes it is useful for problem solvers to annotate plots. Text can be included on a plot to indicate a point of interest or highlight a specific feature of a plot. The code section below builds a simple line plot and applies three annotations (three arrows with text) on the plot.
Matplotlib plots can be saved as image files using the plt. savefig() function. The plt. savefig() function needs to be called right above the plt.
Create a new figure or activate an existing figure. Add an axes to the figure using add_axes() method. Plot the given list. Save the plot using savefig() method.
We can simply save plots generated from Matplotlib using savefig() and imsave() methods. If we are in interactive mode, the plot might get displayed. To avoid the display of plot we use close() and ioff() methods.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With