This is my current simple plot:
As we can see, the ax y is very badly formatted. The time scale on the axis varies only in hour and minutes, hence, I would like to display only the hour and the minutes.
I am trying to use the mdates.DateFormatter as following:
axs.yaxis.set_major_formatter(mdates.DateFormatter('%H:%M'))
but it does not work. This is the outcome:
I think that I am using the right markers '%H:%M'.
Why is it not working?
EDIT:
This is a small reproductible code. The solutions suggested on this post is similar but not the same. The problem there is related to formatting the date, not the time. My problem is getting the time to be correctly formatted as HH:MM.
import pandas as pd
from pandas import Timestamp
import datetime
daux = pd.DataFrame({'resolved_at': {3781: Timestamp('2021-06-04 12:18:00'), 504: Timestamp('2021-04-07 17:39:00'), 4720: Timestamp('2021-06-18 17:28:00'), 6310: Timestamp('2021-07-07 18:38:00'), 4016: Timestamp('2021-06-09 06:22:00'), 4575: Timestamp('2021-06-17 09:34:00'), 3071: Timestamp('2021-05-24 14:42:00'), 3753: Timestamp('2021-06-04 06:32:00'), 5999: Timestamp('2021-07-05 16:51:00'), 141: Timestamp('2021-03-23 21:02:00'), 3320: Timestamp('2021-05-27 10:25:00'), 4267: Timestamp('2021-06-12 16:49:00'), 5130: Timestamp('2021-06-25 07:14:00'), 273: Timestamp('2021-03-27 11:01:00'), 1696: Timestamp('2021-05-03 14:25:00'), 66: Timestamp('2021-03-19 12:59:00'), 4544: Timestamp('2021-06-16 20:32:00'), 5807: Timestamp('2021-07-03 08:18:00'), 1352: Timestamp('2021-04-28 09:55:00'), 5358: Timestamp('2021-06-29 10:14:00'), 3210: Timestamp('2021-05-26 08:42:00'), 2475: Timestamp('2021-05-14 16:41:00'), 5165: Timestamp('2021-06-25 10:23:00'), 715: Timestamp('2021-04-17 09:51:00'), 3227: Timestamp('2021-05-26 10:09:00'), 6085: Timestamp('2021-07-06 09:02:00'), 4009: Timestamp('2021-06-08 20:39:00'), 3541: Timestamp('2021-05-31 18:47:00'), 5788: Timestamp('2021-07-02 22:24:00'), 449: Timestamp('2021-04-06 08:57:00'), 4695: Timestamp('2021-06-18 13:57:00'), 836: Timestamp('2021-04-20 21:07:00'), 4876: Timestamp('2021-06-22 07:58:00'), 4206: Timestamp('2021-06-11 17:56:00'), 3505: Timestamp('2021-05-31 10:49:00'), 3306: Timestamp('2021-05-27 08:52:00'), 1595: Timestamp('2021-05-01 07:59:00'), 2611: Timestamp('2021-05-18 06:27:00'), 5776: Timestamp('2021-07-02 20:02:00'), 180: Timestamp('2021-03-25 05:31:00'), 3633: Timestamp('2021-06-02 08:43:00'), 4502: Timestamp('2021-06-16 12:56:00'), 2031: Timestamp('2021-05-07 10:21:00'), 5625: Timestamp('2021-07-01 17:57:00'), 2393: Timestamp('2021-05-13 06:45:00'), 5675: Timestamp('2021-07-02 08:27:00'), 6187: Timestamp('2021-07-06 21:39:00'), 5077: Timestamp('2021-06-24 12:32:00'), 4531: Timestamp('2021-06-16 17:41:00'), 6132: Timestamp('2021-07-06 14:11:00')},'n_pkgs': {3781: 1, 504: 1, 4720: 1, 6310: 1, 4016: 1, 4575: 2, 3071: 1, 3753: 1, 5999: 1, 141: 1, 3320: 1, 4267: 1, 5130: 1, 273: 1, 1696: 1, 66: 1, 4544: 1, 5807: 1, 1352: 1, 5358: 2, 3210: 1, 2475: 1, 5165: 1, 715: 1, 3227: 1, 6085: 1, 4009: 1, 3541: 2, 5788: 2, 449: 1, 4695: 1, 836: 1, 4876: 1, 4206: 1, 3505: 1, 3306: 1, 1595: 1, 2611: 1, 5776: 2, 180: 1, 3633: 1, 4502: 1, 2031: 1, 5625: 1, 2393: 4, 5675: 2, 6187: 1, 5077: 1, 4531: 1, 6132: 1},'dayofweek': {3781: 4, 504: 2, 4720: 4, 6310: 2, 4016: 2, 4575: 3, 3071: 0, 3753: 4, 5999: 0, 141: 1, 3320: 3, 4267: 5, 5130: 4, 273: 5, 1696: 0, 66: 4, 4544: 2, 5807: 5, 1352: 2, 5358: 1, 3210: 2, 2475: 4, 5165: 4, 715: 5, 3227: 2, 6085: 1, 4009: 1, 3541: 0, 5788: 4, 449: 1, 4695: 4, 836: 1, 4876: 1, 4206: 4, 3505: 0, 3306: 3, 1595: 5, 2611: 1, 5776: 4, 180: 3, 3633: 2, 4502: 2, 2031: 4, 5625: 3, 2393: 3, 5675: 4, 6187: 1, 5077: 3, 4531: 2, 6132: 1}})
import matplotlib.dates as mdates
import matplotlib.pyplot as plt
import seaborn as sns
import matplotlib.dates as mdates
f, axs = plt.subplots(1, 1, figsize=(5,5), sharex=True)
d = daux
d = d[['n_pkgs','dayofweek', 'resolved_at']].pivot('resolved_at', 'dayofweek', 'n_pkgs').fillna(0)
display(d)
g = sns.heatmap(d, ax=axs, cmap='binary')
axs.yaxis.set_major_formatter(mdates.DateFormatter('%H:%M'))
With this snipped of the code, the error is 100% reproducible.
I appreciate all the help so far. Thank you.