本文整理汇总了Python中matplotlib.axes.Axes.axvspan方法的典型用法代码示例。如果您正苦于以下问题:Python Axes.axvspan方法的具体用法?Python Axes.axvspan怎么用?Python Axes.axvspan使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类matplotlib.axes.Axes
的用法示例。
在下文中一共展示了Axes.axvspan方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: highlight_weekends
# 需要导入模块: from matplotlib.axes import Axes [as 别名]
# 或者: from matplotlib.axes.Axes import axvspan [as 别名]
def highlight_weekends(dates: [datetime], ax: Axes):
# first
if dates[0].weekday() == 5 or dates[0].weekday() == 6:
start = dates[0]
else:
start = dates[0] + timedelta(5 - dates[0].weekday())
start = start.replace(hour=0, minute=0, second=0, tzinfo=pytz.utc)
monday = start + timedelta(7 - start.weekday())
monday = monday.replace(hour=0, minute=0, second=0, tzinfo=pytz.utc)
ax.axvspan(start, monday, facecolor='green', edgecolor='none', alpha=0.1)
# middle and last
while True:
saturday = monday + timedelta(5)
if saturday > dates[-1]: # no more weekends
break
monday = saturday + timedelta(2)
if monday > dates[-1]: # log ends during weekend
ax.axvspan(saturday, dates[-1], facecolor='green', edgecolor='none', alpha=0.1)
break
else:
ax.axvspan(saturday, monday, facecolor='green', edgecolor='none', alpha=0.1)