I load CSV data using pandas, where one of the columns takes the form of a date in the format "% a% d.% M.% Y" (for example, "Mon 06.02.2017"), and then try to make some graphs where the X axis marked according to date.
Something goes wrong during plotting because the date stamps are incorrect; for example, what was "Mon 06.02.2017" in the CSV / DataFrame is displayed on the chart as "Thu 06.02.0048".
Here is the MWE. This is the file 'data.csv':
Mon 06.02.2017 ; 1 ; 2 ; 3
Tue 07.02.2017 ; 4 ; 5 ; 6
Wed 08.02.2017 ; 7 ; 8 ; 9
Thu 09.02.2017 ; 10 ; 11 ; 12
Fri 10.02.2017 ; 13 ; 14 ; 15
Sat 11.02.2017 ; 16 ; 17 ; 18
Sun 12.02.2017 ; 19 ; 20 ; 21
Mon 13.02.2017 ; 22 ; 23 ; 24
Tue 14.02.2017 ; 25 ; 26 ; 27
Wed 15.02.2017 ; 28 ; 29 ; 30
Thu 16.02.2017 ; 31 ; 32 ; 33
And this is the 'plot.py' parsing / plot code:
import pandas as pd
import matplotlib.pyplot as plt
import matplotlib.dates as mdates
df = pd.read_csv(
'data.csv',
sep='\s*;\s*',
header=None,
names=['date', 'x', 'y', 'z'],
parse_dates=['date'],
date_parser=lambda x: pd.datetime.strptime(x, '%a %d.%m.%Y'),
engine='python',
)
print df.date
ax1 = df.plot(x='date', y='x', legend=True)
ax2 = df.plot(x='date', y='y', ax=ax1, legend=True)
ax3 = df.plot(x='date', y='z', ax=ax1, legend=True)
ax1.xaxis.set_minor_locator(mdates.DayLocator(interval=1))
ax1.xaxis.set_minor_formatter(mdates.DateFormatter('%a %d.%m.%Y'))
ax1.xaxis.grid(True, which='minor')
plt.setp(ax1.xaxis.get_minorticklabels(), rotation=45)
plt.setp(ax1.xaxis.get_majorticklabels(), visible=False)
plt.tight_layout()
plt.show()
Please note that the DataFrame.date series contains the correct dates, so this is most likely a problem with matplotlib, and not a pandas / parsing error.
, ( ), - LC_TIME = en_US.UTF-8.
, https://www.timeanddate.com/date/weekday.html, 06.02.0048 , - 0048 .
, , .