Как установить временной фильтр для построенного фрейма данных - Matplotlib - PullRequest
0 голосов
/ 03 августа 2020

Я рисую фрейм данных, используя Matplotlib 3.3.0.

index фрейма данных - это объект datetime в следующем формате:

2018-05-29 08:09:00 (т.е. year-month-day hour:minute:second)

Как увеличить временной интервал Ежечасно или Ежедневно или Еженедельно или Ежемесячно ? Я хочу иметь несколько QPushButton, чтобы пользователь мог увеличить или панорамировать до временного отрезка продолжительностью дня или недели, месяца или часа, как показано на изображение.

time-filter buttons

I plot the data-frame as following:

self.canvas.axes.plot(self.df.index, self.df.loc[:, self.comboBox.currentText()], linestyle="None", marker='.')
self.label = self.canvas.axes.set_xlabel('Time', fontsize=9)
self.label = self.canvas.axes.set_ylabel('Temperature - k [°C]', fontsize=9)
self.canvas.axes.legend('Temperature - k [°C]', bbox_to_anchor=(0., 1.02, 1., .102), loc='upper center', ncol=8, mode=None, borderaxespad=0.)

The second problem is that the legend isn't shown completely. Only its first character is displayed. How to fix it?


Updated: I tried plotting the data-frame based on a time element as X-axis like:

self.canvas.axes.plot(self.new_df.index.hour, self.new_df.loc[:, self.comboBox.currentText()])

But, since the values of hours are repeating over each day and over the whole data-frame, then the plot isn't drawn correctly like below picture:

данные нарисованы неправильно из-за повторяющихся значений по оси X

1 Ответ

0 голосов
/ 12 августа 2020

Я нашел фокус:

self.canvas.axes.scatter(df_day.index, df_day.loc[:, item], linestyle="None", marker='.')

self.canvas.axes.xaxis.set_major_locator(matplotlib.ticker.MultipleLocator(0.19))
self.canvas.axes.xaxis.set_major_formatter(mdates.DateFormatter('%d-%b %H:%M'))
...