【发布时间】:2017-03-26 19:41:07
【问题描述】:
我正在使用 matplotlib.pyplot (plt) 绘制温度与时间的关系图。我希望 xticks 只在上午 12 点和下午 12 点出现,matplot 自动选择 xticks 去哪里。
我如何准确地选择每个日期的上午 12 点和下午 12 点,因为我使用的数据没有这些数据点?基本上我想要一个 xtick 在两个数据点之间的点/两个数据点之间的线上。
下面是我的数据和函数的 sn-p。
Temp UNIX Time Time
5.04 1490562000 2017-03-26 22:00:00
3.21 1490572800 2017-03-27 01:00:00
2.15 1490583600 2017-03-27 04:00:00
1.66 1490594400 2017-03-27 07:00:00
6.92 1490605200 2017-03-27 10:00:00
11.73 1490616000 2017-03-27 13:00:00
13.77 1490626800 2017-03-27 16:00:00
def ploting_graph(self):
ax=plt.gca()
xfmt = md.DateFormatter('%d/%m/%y %p')
ax.xaxis.set_major_formatter(locator)
plt.plot(self.df['Time'],self.df['Temp'], 'k--^')
plt.xticks(rotation=10)
plt.grid(axis='both',color='r')
plt.ylabel("Temp (DegC)")
plt.xlim(min(self.df['Time']),max(self.df['Time']))
plt.ylim(min(self.df['Temp'])-1,max(self.df['Temp'])+1)
plt.title("Forecast Temperature {}".format(self.location))
plt.savefig('{}_day_forecast_{}.png'.format(self.num_of_days,self.location),dpi=300)
如您所见,我正在寻找 2017-03-27 00:00:00 和 12:00:00 的 xtick。
我们将不胜感激任何帮助,即使是朝着正确的方向推动也是非常棒的!非常感谢您的先进!
约翰。
【问题讨论】:
标签: python matplotlib dateformatter