Could you please advise on how to solve next Matplotlib xticks ranges & labels issue I am facing with a Python code? I am trying to plot a couple of charts (1 X 2) however, xticks ranges and labels showed are not in the way needed:
Starting point are 4 short dataframes, after import libraries.
I changed and verified data type of the 4 dataframes used (on column YearMo from int64 to datetime64), so they now look as:
YearMo datetime64[ns]
TotSales float64
dtype: object
Python code to plot the 1x2 charts as follow:
fig, ax = plt.subplots(1, 2, figsize=(12, 6))
labelTrial=("Trial Store: "+str(Trial))
labelControl=("Control Store: "+str(Control))
ax[0].plot(ye_mo_sales_Trial2["YearMo"], ye_mo_sales_Trial2["TotSales"], color = "b", label=labelTrial)
ax[0].plot(ye_mo_sales_Control2["YearMo"], ye_mo_sales_Control2["TotSales"], color = "g", label=labelControl)
ax[1].plot(ye_mo_cust_Trial2["YearMo"], ye_mo_cust_Trial2["TotCust"], color = "b", label=labelTrial)
ax[1].plot(ye_mo_cust_Control2["YearMo"], ye_mo_cust_Control2["TotCust"], color = "g", label=labelControl)
ax[0].set_xlabel("Year-Month")
ax[0].set_ylabel("Total Sales")
ax[0].set_title("Trends based on Total Sales")
ax[0].legend()
ax[1].set_xlabel("Year-Month")
ax[1].set_ylabel("Total Customers")
ax[1].set_title("Trends based on Total Customers")
ax[1].legend()
plt.show()
Python Code produce next charts:
At the x axis, I am trying to show a range of 3 points: 2019-02, 2019-03 and 2019-04…however, xaxis shows more than 3 points range and overlapping: see pdf Jupyter enviroment Python code attached where charts are showed. I aready verified dataframes and data they hold so no data error involved.
Thank you in advance for support given.
Alejandro Uribe