MCPcopy Index your code
hub / github.com/matplotlib/matplotlib / YearLocator

Class YearLocator

lib/matplotlib/dates.py:1449–1496  ·  view source on GitHub ↗

Make ticks on a given day of each year that is a multiple of base. Examples:: # Tick every year on Jan 1st locator = YearLocator() # Tick every 5 years on July 4th locator = YearLocator(5, month=7, day=4)

Source from the content-addressed store, hash-verified

1447
1448
1449class YearLocator(RRuleLocator):
1450 """
1451 Make ticks on a given day of each year that is a multiple of base.
1452
1453 Examples::
1454
1455 # Tick every year on Jan 1st
1456 locator = YearLocator()
1457
1458 # Tick every 5 years on July 4th
1459 locator = YearLocator(5, month=7, day=4)
1460 """
1461 def __init__(self, base=1, month=1, day=1, tz=None):
1462 """
1463 Parameters
1464 ----------
1465 base : int, default: 1
1466 Mark ticks every *base* years.
1467 month : int, default: 1
1468 The month on which to place the ticks, starting from 1. Default is
1469 January.
1470 day : int, default: 1
1471 The day on which to place the ticks.
1472 tz : str or `~datetime.tzinfo`, default: :rc:`timezone`
1473 Ticks timezone. If a string, *tz* is passed to `dateutil.tz`.
1474 """
1475 rule = rrulewrapper(YEARLY, interval=base, bymonth=month,
1476 bymonthday=day, **self.hms0d)
1477 super().__init__(rule, tz=tz)
1478 self.base = ticker._Edge_integer(base, 0)
1479
1480 def _create_rrule(self, vmin, vmax):
1481 # 'start' needs to be a multiple of the interval to create ticks on
1482 # interval multiples when the tick frequency is YEARLY
1483 ymin = max(self.base.le(vmin.year) * self.base.step, 1)
1484 ymax = min(self.base.ge(vmax.year) * self.base.step, 9999)
1485
1486 c = self.rule._construct
1487 replace = {'year': ymin,
1488 'month': c.get('bymonth', 1),
1489 'day': c.get('bymonthday', 1),
1490 'hour': 0, 'minute': 0, 'second': 0}
1491
1492 start = vmin.replace(**replace)
1493 stop = start.replace(year=ymax)
1494 self.rule.set(dtstart=start, until=stop)
1495
1496 return start, stop
1497
1498
1499class MonthLocator(RRuleLocator):

Callers 1

get_locatorMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…