本文整理汇总了Python中matplotlib.dates.HourLocator方法的典型用法代码示例。如果您正苦于以下问题:Python dates.HourLocator方法的具体用法?Python dates.HourLocator怎么用?Python dates.HourLocator使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类matplotlib.dates
的用法示例。
在下文中一共展示了dates.HourLocator方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: format_ax
# 需要导入模块: from matplotlib import dates [as 别名]
# 或者: from matplotlib.dates import HourLocator [as 别名]
def format_ax(ax):
"""
Trying to assign reasonable parameters to the time axis.
Parameters
----------
ax:
"""
# TODO: room for improvement
ax.xaxis.set_major_locator(mdates.DayLocator(interval=1))
ax.xaxis.set_major_formatter(fmt)
locator = mdates.HourLocator(interval=4)
locator.MAXTICKS = 5000
ax.xaxis.set_minor_locator(locator)
datemin = pd.Timestamp.utcnow()
ax.set_xlim(datemin)
ax.grid(True)
示例2: ensemble_BG
# 需要导入模块: from matplotlib import dates [as 别名]
# 或者: from matplotlib.dates import HourLocator [as 别名]
def ensemble_BG(BG, ax=None, plot_var=False, nstd=3):
mean_curve = BG.transpose().mean()
std_curve = BG.transpose().std()
up_env = mean_curve + nstd * std_curve
down_env = mean_curve - nstd * std_curve
# t = BG.index.to_pydatetime()
t = pd.to_datetime(BG.index)
if ax is None:
fig, ax = plt.subplots(1)
if plot_var and not std_curve.isnull().all():
ax.fill_between(
t, up_env, down_env, alpha=0.5, label='+/- {0}*std'.format(nstd))
for p in BG:
ax.plot_date(
t, BG[p], '-', color='grey', alpha=0.5, lw=0.5, label='_nolegend_')
ax.plot(t, mean_curve, lw=2, label='Mean Curve')
ax.xaxis.set_minor_locator(mdates.HourLocator(interval=3))
ax.xaxis.set_minor_formatter(mdates.DateFormatter('%H:%M\n'))
ax.xaxis.set_major_locator(mdates.DayLocator())
ax.xaxis.set_major_formatter(mdates.DateFormatter('\n%b %d'))
ax.axhline(70, c='green', linestyle='--', label='Hypoglycemia', lw=1)
ax.axhline(180, c='red', linestyle='--', label='Hyperglycemia', lw=1)
ax.set_xlim([t[0], t[-1]])
ax.set_ylim([BG.min().min() - 10, BG.max().max() + 10])
ax.legend()
ax.set_ylabel('Blood Glucose (mg/dl)')
# fig.autofmt_xdate()
return ax
示例3: tsindex
# 需要导入模块: from matplotlib import dates [as 别名]
# 或者: from matplotlib.dates import HourLocator [as 别名]
def tsindex(ax):
"""
Reset the axis parameters to look nice!
"""
# Get dt in days
dt = ax.get_xlim()[-1] - ax.get_xlim()[0]
if dt <= 1./24.: # less than one hour
pass
elif dt <= 1.: # less than one day
ax.xaxis.set_minor_locator( dates.HourLocator() )
ax.xaxis.set_minor_formatter( dates.DateFormatter(""))
ax.xaxis.set_major_locator( dates.HourLocator( interval=3))
ax.xaxis.set_major_formatter( dates.DateFormatter("%-I %p"))
elif dt <= 7.: # less than one week
ax.xaxis.set_minor_locator( dates.DayLocator())
ax.xaxis.set_minor_formatter( dates.DateFormatter("%d"))
ax.xaxis.set_major_locator( dates.DayLocator( bymonthday=[1, 8, 15, 22]) )
ax.xaxis.set_major_formatter( dates.DateFormatter("\n%b\n%Y") )
elif dt <= 14.: # less than two weeks
ax.xaxis.set_minor_locator( dates.DayLocator())
ax.xaxis.set_minor_formatter( dates.DateFormatter("%d"))
ax.xaxis.set_major_locator( dates.DayLocator( bymonthday=[1, 15]) )
ax.xaxis.set_major_formatter( dates.DateFormatter("\n%b\n%Y") )
elif dt <= 28.: # less than four weeks
ax.xaxis.set_minor_locator( dates.DayLocator())
ax.xaxis.set_minor_formatter( dates.DateFormatter("%d"))
ax.xaxis.set_major_locator( dates.MonthLocator() )
ax.xaxis.set_major_formatter( dates.DateFormatter("\n%b\n%Y") )
elif dt <= 4 * 30.: # less than four months
ax.xaxis.set_minor_locator( dates.DayLocator( bymonthday=[1, 7, 14, 21] ))
ax.xaxis.set_minor_formatter( dates.DateFormatter("%d"))
ax.xaxis.set_major_locator( dates.MonthLocator())
ax.xaxis.set_major_formatter( dates.DateFormatter("\n%b\n%Y") )
else:
ax.xaxis.set_minor_locator( dates.MonthLocator(interval=2) )
ax.xaxis.set_minor_formatter( dates.DateFormatter("%b"))
ax.xaxis.set_major_locator( dates.MonthLocator(bymonth=[1]) )
ax.xaxis.set_major_formatter( dates.DateFormatter("\n%Y"))
return ax