Matplotlib:绘制时间秒是浮点数

时间:2013-12-28 17:53:16

标签: python graph matplotlib

我使用matplotlib创建了几个图表。 X轴始终包含时间,Y轴包含给定值。

图表创建如下:

fig = plt.figure(1)
ax = fig.add_subplot(111)
ax.set_title('Experience Graph')
ax.set_xlabel('Time')
ax.set_ylabel('Experience')
ax.plot(self.timeStorage, teamTotalXP)
ax.fill_between(self.timeStorage,0, teamTotalXP, alpha=0.5)
...
plt.xticks(rotation=20)
plt.savefig(directory + "teams_experience.svg")
plt.clf()

创建时间存储如下:

timeStorage.append(datetime.datetime.utcfromtimestamp(replay.info.game_time))

我在两个不同的Ubuntu实现上试过这个:

Ubuntu 1: The graph I like

Ubuntu 2: The graoh I do not like

可以看出我的第二个版本就像秒钟一样烦人浮动。

额外信息:

  • 两者都在Ubuntu 13.10上运行
  • 我在两个系统中使用相同的python和gcc版本(python 2.7.5+和gcc 4.8.1)
  • matplotlib版本不同!!我的第一个版本在1.2.1之内,第二个版本是1.3.1。 - >我认为这是导致我的问题的原因,但降级我的matplotlib构建似乎很愚蠢......

因此我想知道是否有人知道如何解决我的问题,或者降级是唯一的解决方案。

提前致谢,

Giriel

1 个答案:

答案 0 :(得分:0)

解决方案是使用DateFormatter。 奇怪的是我之前没有这么做过。

查看此答案以获取更多信息: How to change date format using matplolib in python