Matplotlib xticks ranges & labels issue

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

Do you mean that you just want those three ticks? 2019-02, 2019-03 and 2019-04? Your plot above is garbled, so its a little hard to tell what the problem is. Perhaps you just want a MonthLocator?

Thank you Jody, to clarity about your questions attached Jupyter enviroment code to show dataframes are 3 rows X 2 columns all of them.

The 4 dataframes used in my Python code follow same structure and data type showed on the top of the pdf attached document.

At the end of pdf attached document charts (1 X 2) produced by my code are displayed.

On the x axis I want show only 3 year-month points: 2019-02, 2019-03 & 2019-04

Regards,
Alejandro Uribe

···

De: Jody Klymak via Matplotlib nobody@discourse.matplotlib.org
Enviado: lunes, 21 de diciembre de 2020 09:13 p. m.
Para: alejandro_uribe_rodriguez@hotmail.com alejandro_uribe_rodriguez@hotmail.com
Asunto: [Matplotlib] [Community] Matplotlib xticks ranges & labels issue

jklymak
December 21

Do you mean that you just want those three ticks? 2019-02, 2019-03 and 2019-04? Your plot above is garbled, so its a little hard to tell what the problem is. Perhaps you just want a MonthLocator?

matplotlib.org

matplotlib.dates — Matplotlib 3.3.3 documentation

stackoverflow.com
JPV#### MonthLocator in Matplotlibpython, matplotlib
asked by JPV on 12:44AM - 19 Mar 17 UTC

Visit Topic or reply to this email to respond.

To unsubscribe from these emails, click here.


(Attachment Matplotlib xticks ranges & labels issue.pdf is missing)

Sorry for being dense. 1) the Pdf is not attached, 2) I am not clear what you are trying to ask. Did you try using a MonthLocator? Does that not work for you? If not, why not?