Chapter 9: Matplotlib

Custom line color

face William Hunter Josiah Wang

Task 5: What’s your favourite colour?

Now, make the y-plot the colour ‘Blue’, and the z-plot the colour ‘Red’

Hint - watch out for the British (correct) spelling of Colour and the American (incorrect) spelling of Color.

Python only accepts the incorrect spelling…

Custom line color

import numpy as np
import matplotlib.pyplot as plt

resolution = 1000
x = np.linspace(0, 50, resolution)
y = np.sin(x)
z = np.exp(y)

plt.figure(1)
plt.plot(x, y, "b")
plt.plot(x, z, color="r")
plt.title("My Graph")
plt.xlabel("Time (s)")
plt.ylabel("Amplitude (W)")
plt.show()