我有一个基于时间索引的数据框,另一列指出在那个小时发生碰撞时受伤的行人的数量。我正在尝试使用Matplotlib来绘制数据图,并成功地绘制了它,但是,范围太大了。我有一天的数据,并且想要使用最小值和最大值来计算相应的x轴限制。我尝试过使用plt.set_xlim,但出现错误:X轴散点图上的极限范围大熊猫MatplotLib
AttributeError: 'PathCollection' object has no attribute 'set_xlim'
如何正确设置限制?
df = test_request_pandas()
df1 = df[['time','number_of_pedestrians_injured']]
df1.set_index(['time'],inplace=True)
df1 = df1.astype(float)
min = df1.index.min()
max = df1.index.max()
fig = plt.scatter(df1.index.to_pydatetime(), df1['number_of_pedestrians_injured'])
#fig.set_xlim([min, max]) // causing me issues
plt.show()
的[如何更改x轴与MatPlotLib日期时间的范围是多少?(可能的复制http://stackoverflow.com/questions/21423158/how-do-i-change-the- x-axis-with-datetimes-in-matplotlib) –