How to set up Pandas Date Time Stamp @ x-axis

When I draw full data, it works fine and displays the date on the x axis:

1.

When I zoom in to a specific part to view:
2

the graph shows only time, not the date, I understand that with a smaller number of points, a different set of dates cannot be displayed, but how to display the date or set the date format, even if the graph is enlarged?

dataToPlot = pd.read_csv(fileName, names=['time','1','2','3','4','plotValue','6','7','8','9','10','11','12','13','14','15','16'], 
                             sep=',', index_col=0, parse_dates=True, dayfirst=True)
dataToPlot.drop(dataToPlot.index[0])
startTime = dataToPlot.head(1).index[0]
endTime = dataToPlot.tail(1).index[0]
ax = pd.rolling_mean(dataToPlot_plot[startTime:endTime][['plotValue']],mar).plot(linestyle='-', linewidth=3,  markersize=9, color='#FECB00')

Thanks in advance!

+4
source share
1 answer

I have a solution for the labels to look consistent, although keep in mind that it will also include time on a “larger scale” timeline.

matplotlib.dates, x. : matplotlib, df.plot, plt.plot_date .

import pandas as pd

import matplotlib.pyplot as plt
from matplotlib import dates

# Generate some random data and plot it

time = pd.date_range('07/11/2014', periods=1000, freq='5min')
ts = pd.Series(pd.np.random.randn(len(time)), index=time)

fig, ax = plt.subplots()

ax.plot_date(ts.index.to_pydatetime(), ts.data)

# Create your formatter object and change the xaxis formatting.

date_fmt = '%d/%m/%y %H:%M:%S'

formatter = dates.DateFormatter(date_fmt)
ax.xaxis.set_major_formatter(formatter)

plt.gcf().autofmt_xdate()

plt.show()

,

enter image description here

.

enter image description here

+6

Source: https://habr.com/ru/post/1548038/


All Articles