'Plotting Treasury Yield Curve, how to overlay two yield curves using matplotlib

I am trying to create a graph of the treasury yield curve to compare the rates from two separate dates. I am having difficulty with combining the two curves and creating a clean graph. My question: how do I plot the two yield curves together, with the yields (rates) are on the y-axis, and the maturities (2yr, 5yr, 10yr, 20yr, 30yr) are on the x-axis?

import numpy as np
import pandas as pd
import datetime as dt
import pandas.io.data as web
import matplotlib.pyplot as plt
import quandl as q
from pandas import DataFrame
import matplotlib
matplotlib.style.use('ggplot')

treasury = q.get("USTREASURY/YIELD", trim_start="2000-01-01", returns="pandas")

fig, ax = plt.subplots()

treas = DataFrame(treasury)
treas.drop(treas.columns[[0,1,2,3,5,7]], axis=1, inplace=True)
today = treas.iloc[-1:]
first = treas.iloc[:1]
first = first.T
today = today.T

ax.plot(first, 'o')
ax.plot(today, 'x')

#first.plot(marker='o')
#today.plot(marker='o')
plt.show()


Solution 1:[1]

FYI: I'm using python 3.8 and spyder with anaconda. I spent a lot of time troubleshooting the 'module not found error for Quandl only to discover it should be quandl (lowercase).

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Chuck