You learned from your study of online Jupyter Notebook tutorials that you can include both code and markdown text (such as this text) in your notebook.
The following code from the prerequisite course shows how to use a plt.show statement to display a figure. The code also shows how use the plt.savefig statement to save a copy of the figure to a jpg file, which can be viewed using any standard image viewer.
This code, in conjunction with the code in the file named DisplayFig02 shows three different ways to display figures:
As you can see, this markdown also shows how to create a bullet list.
The main point of this example, however, is to show that it is not necessary to put all of the code in a single code cell. While it may or may not be a good idea to do so, you can break the code into smaller code cells with markdown cells in between.
Let's begin by putting our import statements in a cell by themselves.
import numpy as np
import matplotlib.pyplot as plt
Now we will insert this markdown cell with some explanatory text.
The code in the following cell computes and plots some data in a figure. It also prints some information about the figure.
t = np.arange(0, 6.0, 0.05)
plt.plot(t, np.exp(-t) * np.cos(2*np.pi*t))
print(plt.gcf())#Get a reference to the current figure.
The code in the following cell causes the figure to be saved in an output jpg file. It also causes the figure to be displayed in the notebook.
If you pull down the Kernel menu and select Restart & Run All, the code will be executed from the top to the bottom of the notebook producing the results that you see here.
plt.savefig('EmbedCode01.jpg')
plt.show()
Author: Prof. Richard G. Baldwin
Affiliation: Professor of Computer Information Technology at Austin Community College in Austin, TX.
File: EmbedCode01.html
Revised: 05/13/18
Copyright 2018 Richard G. Baldwin