
# Line charts are a good choice for showing trends

# We can add COLORS to the lines

# Data 1:
variance = [1, 2, 4, 8, 16, 32, 64, 128, 256]

# Data 2:
bias_squared = [256, 128, 64, 32, 16, 8, 4, 2, 1]

# Sum of value is the data sets
total_error = [x + y for x, y in zip(variance, bias_squared)]

# Makes: [0, 1, 2, ....] for ticks on x-axis
xs = [i for i, _ in enumerate(variance)]

from matplotlib import pyplot as plt

# we can make multiple calls to plt.plot
# to show multiple series on the same chart

plt.plot(xs, variance,     'g-' , label='variance'   ) # green solid line
plt.plot(xs, bias_squared, 'r-.', label='bias^2'     ) # red dot-dashed line
plt.plot(xs, total_error,  'b:' , label='total error') # blue dotted line

# because we've assigned labels to each series
# we can get a legend for free

plt.legend(loc=9)                    # loc=9 means "top center"

plt.xlabel("model complexity")
plt.title("The Bias-Variance Tradeoff")

plt.show()
