1""" 2=============================== 3Legend using pre-defined labels 4=============================== 5 6Defining legend labels with plots. 7""" 8 9 10import numpy as np 11import matplotlib.pyplot as plt 12 13# Make some fake data. 14a = b = np.arange(0, 3, .02) 15c = np.exp(a) 16d = c[::-1] 17 18# Create plots with pre-defined labels. 19fig, ax = plt.subplots() 20ax.plot(a, c, 'k--', label='Model length') 21ax.plot(a, d, 'k:', label='Data length') 22ax.plot(a, c + d, 'k', label='Total message length') 23 24legend = ax.legend(loc='upper center', shadow=True, fontsize='x-large') 25 26# Put a nicer background color on the legend. 27legend.get_frame().set_facecolor('#00FFCC') 28 29plt.show() 30