0

I'd like to have this code organization

# 1st cell showing my intentions
plt.plot(t, f(t))

(NO OUTPUT)

and

# 2nd cell with boring details
plt.xlabel(...)
...
plt.show()

(the plot with all the now interesting details)

because I plan to use the notebook to produce slides and/or pdf using an extension that allows to hide the input cell only, so that my reader sees only what I want to show of my code ­— they can look at the notebook itself to see what's going on behind the scene…

I've tried plt.hold() but it's not what I had in mind…

gboffi
  • 22,939
  • 8
  • 54
  • 85
  • You may capture the output of a jupyter cell by putting `%%capture` in the first line of it. – ImportanceOfBeingErnest May 03 '18 at 11:52
  • @ImportanceOfBeingErnest It seems to me that the implementation of `%%capture` is buggy — following `%%capture my_plot` I should be able to access a member `my_plot.outputs` containing the rich display obiects that I can pass to `display`, but it does not work, IPython raises an exception if I try to access that property. Further, I suspect that the object that is saved is a bitmap of the plot rather than the matplotlib `ax`. – gboffi May 03 '18 at 12:20
  • I'm not sure I understand this. My suggestion was to use `%%capture` without any appenix. – ImportanceOfBeingErnest May 03 '18 at 12:22
  • @ImportanceOfBeingErnest I want to suppress the plot in a cell and in the next cell I want to modify it and eventually display the modified (in my example i added an x label) plot. ፨ I built on your comment, that did not address this side of my problem, trying to find a solution to _my problem_. Do my previous comment make sense now? – gboffi May 03 '18 at 12:30
  • I currently don't see the problem. Capture the output from the first cell, but don't capture the output from the second. – ImportanceOfBeingErnest May 03 '18 at 12:33
  • I guess [this is what I'm talking about](https://stackoverflow.com/questions/44118059/how-to-add-plot-commands-to-a-figure-in-more-than-one-cell-but-display-it-only). – ImportanceOfBeingErnest May 03 '18 at 12:41
  • Or better [the complete solution](https://stackoverflow.com/questions/45760693/how-to-overlay-plots-from-different-cells). – ImportanceOfBeingErnest May 03 '18 at 12:45
  • @ImportanceOfBeingErnest Your 1st comment was not helpful (trust me). The links to your previous answers, on the other hand... especially the `%config InlineBackend...` trick! – gboffi May 03 '18 at 12:57

0 Answers0