Display figure with a show statement

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:

  • With a plt.show statement.
  • With a magic #matplotlib notebook statement.
  • By writing the figure into an output jpg file.

As you can see, this markdown also shows how to create a bullet list.

In [1]:
import numpy as np
import matplotlib.pyplot as plt

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.

plt.savefig('DisplayFig01.jpg')
plt.show()
Figure(432x288)

Housekeeping material

Author: Prof. Richard G. Baldwin

Affiliation: Professor of Computer Information Technology at Austin Community College in Austin, TX.

File: DisplayFig01.html

Revised: 05/10/18

Copyright 2018 Richard G. Baldwin