Hours and hours trying to find this error. I’m now just guessing. I have indicated the full error. I’ve looke at the data.
Python prints out the values correctly
I did try to plot only the one variable rather than the full plot:
There are 6 columns of data: DATE EFFR RPONTSYD RRPONTSYD RPTSYD RRPTSYD
Matplotlib has no problem plotting the last 4 variable: RPONTSYD RRPONTSYD RPTSYD RRPTSYD
But the line for plotting the first variable EFFR triggers the error:
TypeError: ‘value’ must be an instance of str or bytes, not a float
EFFR is the first variable after DATE, so I’m thinking that the problem is the date format: the date in csv file is m/d/Y but python records it as Y/m/d
effrate = stirs.loc[:,“EFFR”]
I’ve deleted last row of the excel sheet, I’ve looked at the EFFR column for anomalies
I’ve tried plotting EFFR alone: and get the same error
plt.figure(figsize=(5, 2.7), layout=‘constrained’)
plt.plot(x, effrate, label=‘Fed Funds’)
When I plot all five variables, I get the same error for EFFR
fig, ax1 = plt.subplots()
color1 = ‘tab:red’
color = ‘tab:blue’
color2 = ‘tab:green’
ax1.set_xlabel(‘Date’)
ax1.set_ylabel(‘Percent (x.xx)’, color=color1)
ax1.tick_params(axis=‘y’, labelcolor=color)
lns1 = ax1.plot(stirs[‘DATE’], effrate, label=‘EFFR’,linestyle =’–’,linewidth=.5, color=‘c’)
lns2 = ax1.plot(stirs[‘DATE’], repo, label=‘Repos’,linestyle =’–’,linewidth=.5, color=‘b’)
lns3 = ax1.plot(x, mrepo, label=‘Repos_OMO’,linestyle =’-.’, linewidth=.75, color=‘g’)
ax2 = ax1.twinx()
ax2.set_ylabel(‘Level’, color=color)
ax2.tick_params(axis=‘y’, labelcolor=color)
instantiate a second axes that shares the same x-axis
lns4 = ax2.plot(x, rrepo, label=‘Reverse repo’,linestyle =’–’, linewidth=.3,color=‘k’)
lns5 = ax2.plot(x, mrrepo, label=‘Reverse Repos_OMO’,linestyle =’-.’, linewidth=.2,color=‘m’)
lns = lns1+lns2+lns3+lns4+lns5
labs = [l.get_label() for l in lns]
plt.legend(lns, labs, loc=0)
plt.title(“Effective FF rate, repo, reverse repo”)
plt.legend()
If I plot only the last 4 variables, the plot is fine
···
Nancy Hammond, Ph.D
nahammond@gmail.com
312.989.3854