I have a dataframe that is indexed based on time, with another column indicating the number of injured pedestrians during a crash occuring at that hour. I am trying to use Matplotlib in order to graph the data, and have successfully graphed it, however, the range is much too large. I have data for one day, and would like to set the x axis limit accordingly using the min and max values calculted. I have tried using plt.set_xlim but I get an error:
AttributeError: 'PathCollection' object has no attribute 'set_xlim'
How can the limit be properly set?
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()