熊猫绘图日期频率

时间:2017-10-22 03:05:07

标签: python pandas matplotlib plot

我是Pandas的新手,并尝试从DataFrame中绘制一些数据,但希望所有DateTime值在x轴上都可见。但是,当我绘制数据时,我只看到了25个DateTimes中的5个。如何指定在x轴上显示所有日期时间?下面是我的代码以及生成的图表,它只显示了25个日期时间中的5个。

我的DataFrame

0                  Degrees
10/21 14:55        93.1
10/21 15:10        92.3
10/21 15:25        93.5
10/21 15:40        95.2
10/21 15:55        93.1
10/21 16:10        93.8
10/21 16:25        95.1
10/21 16:40        90.8
10/21 16:55        91.1
10/21 17:10        92.4
10/21 17:25        94.3
10/21 17:40        94.6
10/21 17:55        94.6
10/21 18:10        95.5
10/21 18:25        98.6
10/21 18:40        95.7
10/21 18:55        97.0
10/21 19:10        95.8
10/21 19:25        96.6
10/21 19:40        95.7
10/21 19:55        91.3
10/21 20:10        95.6
10/21 20:25        97.6
10/21 20:40        95.3
10/21 20:55        95.3

代码:

import pandas as pd
desired_width = 400
pd.set_option('display.width', desired_width)
import matplotlib.pyplot as plt
from pylab import rcParams
import re

rcParams['figure.figsize'] = 12, 6
fig = plt.figure()
ax = fig.add_subplot(111)

df.Degrees.plot(kind='line', color='maroon', linestyle='--', alpha=0.5, marker='o', label="Test Report")

ax.legend(loc='lower right')
ax.legend(loc="lower left", fontsize=9, bbox_to_anchor=(0.0, 0.060))
ax.tick_params(axis='both', which='both', labelsize=7.5)
plt.tight_layout()
fig.autofmt_xdate()
plt.show()
plt.close()

图表输出:

enter image description here

0 个答案:

没有答案
相关问题