Common Mistakes

Week 8 - Plotting

1. Missing import

In the context of this course, we mostly use pyplot sublibrary of the matplotlib library of Python. Missing the import prohibits the array inputs, such as x and y, from being processed into an image. Please take a look at the example below.

# incorrect example

x = [1, 2, 3, 4, 5]

y = [1, 4, 9, 16, 25]

plt.plot(x,y)

plt.show()

This will result in the error below.

----> 4 plt.plot(x,y)

      5 plt.show()

NameError: name 'plt' is not defined

We can fix this issue simply by adding the import necessary. 

# correct example

x = [1, 2, 3, 4, 5]

y = [1, 4, 9, 16, 25]

import matplotlib.pyplot as plt

plt.plot(x,y)

plt.show()

2. Missing the specific features in the instructions

In some assignments, you may be asked about a few specific features, such as labelling the horizontal axis with a given text, vertical, or something else. If these specific features are missing from your plot, you may lose a grade during evaluation. So use the instructions as a checklist to see if you have done the things asked of you, and try to work on the things that are still missing.