Introduction to NumPy and Matplotlib
Chapter 9: Matplotlib
Legends
Task 6: You are a legend!
Add a legend onto the graph to make sure you can tell which is y
and z
. Place the legend in the top centre of the figure.
See this documentation on how to do this!
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.legend(["y", "z"], loc="upper center")
plt.title("My Graph")
plt.xlabel("Time (s)")
plt.ylabel("Amplitude (W)")
plt.show()