【发布时间】:2019-04-23 14:21:00
【问题描述】:
import matplotlib.pyplot as plt
import datetime
x = [datetime.datetime(1943,3, 13,12,0,0),
datetime.datetime(1943,3, 13,12,5,0),
datetime.datetime(1943,3, 13,12,10,0),
datetime.datetime(1943,3, 13,12,15,0),
datetime.datetime(1943,3, 13,12,20,0),
datetime.datetime(1943,3, 13,12,25,0),
datetime.datetime(1943,3, 13,12,30,0),
datetime.datetime(1943,3, 13,12,35,0)]
y = [1,2,3,4,2,1,3,4]
# plot the data out but does not provide sufficient detail on the lower values
plt.figure()
plt.bar(x,y)
# plot the data out but ommit the datetime information
plt.figure()
plt.bar(range(0,len(x)),y)
大家好,我刚从 matplotlib 开始,从 matlab 过渡到 python。但是,我遇到了 matplotlib 的奇怪行为,因为它无法与 datetime 元素一起显示数据。 我的问题是两个条形图的输出都会产生两个不同的结果。
第一个直接将数据转换为某种连续数据,而第二个更像分类数据。有没有人遇到过和我类似的问题并且不介意分享他们的解决方法?
P/s:我试过 seaborn,它可以工作,但不知何故不能很好地用于双轴绘图。我也搜索过类似的问题,但不知何故不是这样的问题?
【问题讨论】:
标签: python datetime matplotlib bar-chart visualize