我已经创建了一个函数,该函数应在投资的条形图上叠加累积收益的折线图(如下)。但是,该函数在尝试创建Barplot时(在代码下方)返回错误。
def cumulative_graph():
fig, ax1 = plt.subplots()
idx1 = deposits.set_index(['Date'])
ax1 = sns.barplot(deposits['Date'], deposits['cumulin'])
ax1.set_xlabel('Date')
ax1.set_ylabel('Cumulative investments (EUR)', color='r')
ax1.tick_params('y', colors='r')
cumgroup = grouped.cumsum()
ax2 = ax1.twinx()
ax2 = sns.lineplot(idx,cumgroup)
ax2.set_ylabel('Cumulative interest (EUR)', color='b')
ax2.tick_params('y', colors='b')
plt.title('Cumulative interest and investments')
它返回以下错误:
ValueError: view limit minimum -36848.920000000006 is less than 1 and is an
invalid Matplotlib date value. This often happens if you pass a non-datetime
value to an axis that has datetime units
我尝试重新格式化存款数据框的日期列,并将其用作索引,但是没有运气。我已经确认该列的确是日期时间格式。我该如何克服这个问题?