Don't save the predictions.plot()
output into ax
. You will simply get a list of lines. After implementing the solution below, you can view the output using plt.show()
.
When dealing with dates that are datetime
objects
For labels with 'Jul 2021', 'Aug 2021', etc, use
import datetime
import matplotlib.pyplot as plt # Matplotlib.pyplot object
# Please note that df is a DataFrame object. Substitute your DataFrame object's name below.
dates_index = df.index
# You can use df.index in the list comprehension as well as in the plt.plot and plt.xticks operations as an alternative to dates_index.
labels = [f'{date.strftime("%b")} {date.strftime("%Y")}' for date in dates_index]
print(labels)
plt.plot(y=['Actual','add_add','add_mul','mul_add','mul_mul','Philips'],figsize=(5,4),
legend=True,color=['b','r','g','m','y','black'],ylabel='Quantity',xlabel='Date')
plt.xticks(dates_index, labels)
plt.show() # Visualize the plot
For labels with 'Jul 21', 'Aug 21', etc, use
import datetime
import matplotlib.pyplot as plt # Matplotlib.pyplot object
# Please note that df is a DataFrame object. Substitute your DataFrame object's name below.
dates_index = df.index
# You can use df.index in the list comprehension as well as in the plt.plot and plt.xticks operations as an alternative to dates_index.
labels = [f'{date.strftime("%b")} {date.strftime("%y")}' for date in dates_index]
print(labels)
plt.plot(y=['Actual','add_add','add_mul','mul_add','mul_mul','Philips'],figsize=(5,4),
legend=True,color=['b','r','g','m','y','black'],ylabel='Quantity',xlabel='Date')
plt.xticks(dates_index, labels)
plt.show() # Visualize the plot
For labels with 'Jul', 'Aug', etc, use
import datetime
import matplotlib.pyplot as plt # Matplotlib.pyplot object
# Please note that df is a DataFrame object. Substitute your DataFrame object's name below.
dates_index = df.index
# You can use df.index in the list comprehension as well as in the plt.plot and plt.xticks operations as an alternative to dates_index.
labels = [f'{date.strftime("%b")}' for date in dates_index]
print(labels)
plt.plot(y=['Actual','add_add','add_mul','mul_add','mul_mul','Philips'],figsize=(5,4),
legend=True,color=['b','r','g','m','y','black'],ylabel='Quantity',xlabel='Date')
plt.xticks(dates_index, labels)
plt.show() # Visualize the plot
When dealing with dates that are str
objects
For labels with 'Jul 2021', 'Aug 2021', etc, use
import datetime
import matplotlib.pyplot as plt # Matplotlib.pyplot object
# Please note that df is a DataFrame object. Substitute your DataFrame object's name below.
dates_index = df.index
# You can use df.index in the list comprehension as well as in the plt.plot and plt.xticks operations as an alternative to dates_index.
labels = [f'{(datetime.datetime.strptime(date, "%Y-%m-%d")).strftime("%b")} {datetime.datetime.strptime(date, "%Y-%m-%d").year}' for date in dates_index]
print(labels)
plt.plot(y=['Actual','add_add','add_mul','mul_add','mul_mul','Philips'],figsize=(5,4),
legend=True,color=['b','r','g','m','y','black'],ylabel='Quantity',xlabel='Date')
plt.xticks(dates_index, labels)
plt.show() # Visualize the plot
For labels with 'Jul 21', 'Aug 21', etc, use
import datetime
import matplotlib.pyplot as plt # Matplotlib.pyplot object
# Please note that df is a DataFrame object. Substitute your DataFrame object's name below.
dates_index = df.index
# You can use df.index in the list comprehension as well as in the plt.plot and plt.xticks operations as an alternative to dates_index.
labels = [f'{(datetime.datetime.strptime(date, "%Y-%m-%d")).strftime("%b")} {datetime.datetime.strptime(date, "%Y-%m-%d").strftime("%y")}' for date in dates_index]
print(labels)
plt.plot(y=['Actual','add_add','add_mul','mul_add','mul_mul','Philips'],figsize=(5,4),
legend=True,color=['b','r','g','m','y','black'],ylabel='Quantity',xlabel='Date')
plt.xticks(dates_index, labels)
plt.show() # Visualize the plot
For labels with 'Jul', 'Aug', etc, use
import datetime
import matplotlib.pyplot as plt # Matplotlib.pyplot object
# Please note that df is a DataFrame object. Substitute your DataFrame object's name below.
dates_index = df.index
# You can use df.index in the list comprehension as well as in the plt.plot and plt.xticks operations as an alternative to dates_index.
labels = [f'{(datetime.datetime.strptime(date, "%Y-%m-%d")).strftime("%b")}' for date in dates_index]
print(labels)
plt.plot(y=['Actual','add_add','add_mul','mul_add','mul_mul','Philips'],figsize=(5,4),
legend=True,color=['b','r','g','m','y','black'],ylabel='Quantity',xlabel='Date')
plt.xticks(dates_index, labels)
plt.show() # Visualize the plot