Plt.show() Is Empty When The Plt.plot() Calls Are Done In Other Cells
Solution 1:
This is normal behavior for the Jupyter Notebook. It expects all the commands for one plot to be in the same cell, and then when the cell ends, it renders the plot. That's why you don't need plt.show()
. By the way, you only need the IPython magic command %matplotlib inline
once per notebook, unless you want to switch between different display modes.
To annotate every line of plotting commands, you could of course just use Python comments within the cell. If you have to use Markdown, a simple workaround is to enumerate the command lines by number comments, or just set notes at certain important lines, and then refer to these numbers in the next Markdown cell.
Note that this annotation problem is not specific to plots. For example, how would you annotate every line of a function definition? The whole definition has to be in one cell.
Solution 2:
If you do not want to use fig
and ax
, then a (maybe not very elegant) solution but easier to explain would be to edit the last cell as following:
plt.plot(x_values, doubles, x_values, squares)
instead of
plt.plot()
Post a Comment for "Plt.show() Is Empty When The Plt.plot() Calls Are Done In Other Cells"