Reputation: 1545
If I have the following example Python code using a Pandas dataframe:
import pandas as pd
from datetime import datetime
ts = pd.DataFrame(randn(1000), index=pd.date_range('1/1/2000 00:00:00', freq='H', periods=1000), columns=['Data'])
ts['Time'] = ts.index.map(lambda t: t.time())
ts = ts.groupby('Time').mean()
ts.plot(x_compat=True, figsize=(20,10))
The output plot is:
What is the most elegant way to get the X-Axis ticks to automatically space themselves hourly or bi-hourly? x_compat=True
has no impact
Upvotes: 2
Views: 3931
Reputation: 58895
You can pass to ts.plot()
the argument xticks
. Giving the right interval you can plot hourly our bi-hourly like:
max_sec = 90000
ts.plot(x_compat=True, figsize=(20,10), xticks=arange(0, max_sec, 3600))
ts.plot(x_compat=True, figsize=(20,10), xticks=arange(0, max_sec, 7200))
Here max_sec
is the maximum value of the xaxis
, in seconds.
Upvotes: 3