I use IPython notebooks with matplotlib.pyplot, and I often create a plot that needs to generate a fairly large block of code. Then I would like to save the object and use the same pair of shapes / axes to later include in another plot.
For example, suppose I have an xy data pair for a scatter plot. I would like to show the points, and then a few cells later - potentially with other calls on pyplot, to make other, unrelated shapes - I would like to show this shape again so that I can draw a regression line or some other graphics above it.
In the picture that I gave below, I have a short notebook; I want the shape from cell # 2 to be drawn in cell # 3 without again calling pyplot.scatter.
Essentially, I want to show the shape again without repeating all the code. What are my options for this? I was not able to accomplish this using show () or draw () calls or by setting the current shape object in a cell as my saved shape object. Any advice is appreciated. Thanks!
PS I know that if I reuse a figure and the graph above it, the object will change, and therefore the state of the fig object may not correspond to the plot that was drawn in the previous IPython cell. This is good for my work.
IPython notebook example
matplotlib ipython jupyter-notebook jupyter
Christopher krapu
source share