我正在绘制time
和value
之间的图表。我希望这些time
标签显示为2018-06-30 18:35:45
作为主要的csv数据。
相反,x轴上的图形将time
显示为06:30 20
。
X轴的标号如何才能像主要数据中提到的那样精确。
我使用的代码是:
import pandas as pd
import matplotlib.pyplot as plt
df = pd.read_csv('Mlogi_ALL_idle_day.csv')
df['time']=pd.to_datetime(df['time'], unit='ns')
x = df['time']
y = df['d']
fig, ax = plt.subplots()
ax.plot_date(x, y, linestyle='-')
plt.title('Idle for 1 July - 2 July 2018')
plt.legend()
plt.ylabel('duration')
plt.xlabel('Time')
fig.autofmt_xdate()
plt.show()
数据看起来像这样:
In[10]:df.head()
Out[10]:
time d
0 2018-06-30 18:35:45 41000000000
1 2018-06-30 18:36:47 44000000000
2 2018-06-30 18:37:46 43000000000
3 2018-06-30 18:38:46 40000000000
4 2018-06-30 18:39:47 43000000000
发布于 2018-08-13 08:51:50
若要更改主要x轴刻度的日期标签,可以使用
ax.xaxis.set_major_formatter(mdates.DateFormatter('%Y-%m-%d %H:%M:%S'))
https://stackoverflow.com/questions/51796496
复制相似问题