пользователь определяет временной шаг в локаторе данных в matplotlib.

#date #datetime #matplotlib #format #xticks

Вопрос:

У меня есть этот фрейм данных:

 dates,AA,BB
2018-04-02 00:00:00,0.02,1.72
2018-04-02 01:00:00,0.02,1.72
2018-04-02 02:00:00,0.02,1.72
2018-04-02 03:00:00,0.02,1.72
2018-04-02 04:00:00,0.02,1.72
2018-04-02 05:00:00,0.02,1.72
2018-04-02 06:00:00,0.02,1.72
2018-04-02 07:00:00,0.02,1.72
2018-04-02 08:00:00,0.02,1.72
2018-04-02 09:00:00,0.02,1.72
2018-04-02 10:00:00,0.02,1.72
2018-04-02 11:00:00,3,1.72
2018-04-02 12:00:00,0.02,1.72
2018-04-02 13:00:00,0.02,1.72
2018-04-02 14:00:00,5,1.72
2018-04-02 15:00:00,0.02,1.72
2018-04-02 16:00:00,0.02,1.72
2018-04-02 17:00:00,0.02,1.72
2018-04-02 18:00:00,0.02,1.72
2018-04-02 19:00:00,0.02,1.72
2018-04-02 20:00:00,0.02,1.72
2018-04-02 21:00:00,0.02,1.72
2018-04-02 22:00:00,0.02,1.72
2018-04-02 23:00:00,5,1.72
2018-04-03 00:00:00,0.02,1.72
2018-04-03 01:00:00,0.02,1.72
2018-04-03 02:00:00,0.02,1.72
2018-04-03 03:00:00,0.02,1.72
2018-04-03 04:00:00,0.02,1.72
2018-04-03 05:00:00,6,1.72
2018-04-03 06:00:00,0.02,1.72
2018-04-03 07:00:00,0.02,1.72
2018-04-03 08:00:00,0.02,1.72
2018-04-03 09:00:00,0.02,1.72
2018-04-03 10:00:00,0.02,1.72
2018-04-03 11:00:00,0.02,1.72
2018-04-03 12:00:00,0.02,1.72
 

Я хотел бы построить график данных, но с x-локатором в x ax в соответствии с временным шагом, определенным мной самим.

Для этого я попытался сделать следующее:

 plt.rc('font', family='sans',size=10)
matplotlib.rc('text', usetex=True)
matplotlib.rc('legend', fontsize=10) 
matplotlib.rcParams['text.latex.preamble'] = [r'boldmath']
#------------------------------------------------------------------------------

    
dfr = pd.read_csv('test_2.csv', sep=',', header = 0, index_col=0, parse_dates=True)


fig, ax = plt.subplots()

ax.plot(dfr.index.values,dfr['AA'].values)

locs = dates.HourLocator()
ax.xaxis.set_major_formatter(dates.DateFormatter(r'textbf{%d %H:%M}')) 
ax.xaxis.set_major_locator(locs)
plt.setp(ax.get_xticklabels(), rotation=90)
 

То, что я получаю, — это не то, чего я хочу:

введите описание изображения здесь

In order to get what I want, I have done the following:

 locator = mdates.AutoDateLocator(minticks=2, maxticks=12)
formatter = mdates.ConciseDateFormatter(locator)
ax.xaxis.set_major_locator(locator)
ax.xaxis.set_major_formatter(formatter)
 

This is the result:

enter image description here

However, this is not the thing that I want. I would like to have all the labels of the ticks in bold.
How can I merge the two methodology to get what I want.

Thanks for any kind of help