1

I have the following code that is showing the column name for the first plot, rather than the label name. Any guidance welcome on how to fix this.

sales_pred = results2.get_prediction(start=pd.to_datetime('2011-10-28'), dynamic=False)

pred_ci = sales_pred.conf_int()

ax = pivot_sales['2010':].plot(label='Actual Sales')
sales_pred.predicted_mean.plot(ax=ax, label='Sales Prediction', alpha=.7, figsize=(14, 4))

ax.fill_between(pred_ci.index,
                pred_ci.iloc[:, 0],
                pred_ci.iloc[:, 1], color='k', alpha=.2)

ax.set_xlabel('Date')
ax.set_ylabel('Weekly Sales')
plt.legend()
plt.show()

The legend should show Actual Sales, rather than Weekly_Sales.

enter image description here

bigbounty
  • 16,526
  • 5
  • 37
  • 65
Omar
  • 27
  • 5
  • Pandas do some automatic labelling. If `pivot_sales['2010':]` returns a Series, you can use `pivot_sales['2010':].rename("Actual Sales").plot()`. – paime Jul 08 '20 at 07:39
  • Thanks @paime it returns a datetime indexed Series. I used .rename() as suggested and received an error regarding the index. Sorry - I should have copy and pasted it, but to re-run through to get to the error message takes a long while. – Omar Jul 09 '20 at 16:49
  • It is difficult to help without being able to try it. You should work on providing a [reproducible example](https://stackoverflow.com/questions/20109391/how-to-make-good-reproducible-pandas-examples). Only dummy data that mocks your actual `results2` data is required. And maybe by working on creating the reproducible example you'll be able to spot the bug by yourself. – paime Jul 09 '20 at 17:05

0 Answers0