TWO LINES AND A LEGEND IN MATPLOTLIB
Listing 5.11 displays the contents of plotgrid2.py that illustrates how to display a colored grid.
Listing 5.11: two_lines_legend.py
import matplotlib.pyplot as plt
# FIRST PLOT:
vals_x = [91,93,95,96,97,98,99,99,104,115]
vals_y = [1500,2000,3000,2500,1200,1500,2900,3200,5200,6500]
plt.plot(vals_x, vals_y) # alternate style
#plt.plot(vals_x, vals_y, label='First List')
# SECOND PLOT:
vals_x2 = [91,93,95,96,97,98,99,99,104,115]
vals_y2 = [1005,1006,1007,1008,1009,2031,3100,2033,3034,4035]
plt.plot(vals_x2, vals_y2)
#plt.plot(vals_x2, vals_y2, label='Second List') # alternate style
# generate line plot:
plt.plot(vals_x, vals_y)
plt.title("Random Pairs of Numbers")
plt.xlabel("Random X Values")
plt.ylabel("Random Y Values")
plt.legend(['First List','Second List'])
#plt.legend() # alternate style
plt.show()
Listing 5.11 defines the NumPy variable data that defines a 2D set of points...