matplotlib/matplotlib · error · TypeError
tz must be string or tzinfo subclass, not {tz!r}.
Error message
tz must be string or tzinfo subclass, not {tz!r}. What it means
Error "tz must be string or tzinfo subclass, not {tz!r}." thrown in matplotlib/matplotlib.
Source
Thrown at lib/matplotlib/dates.py:224
def _get_tzinfo(tz=None):
"""
Generate `~datetime.tzinfo` from a string or return `~datetime.tzinfo`.
If None, retrieve the preferred timezone from the rcParams dictionary.
"""
tz = mpl._val_or_rc(tz, 'timezone')
if tz == 'UTC':
return UTC
if isinstance(tz, str):
tzinfo = dateutil.tz.gettz(tz)
if tzinfo is None:
raise ValueError(f"{tz} is not a valid timezone as parsed by"
" dateutil.tz.gettz.")
return tzinfo
if isinstance(tz, datetime.tzinfo):
return tz
raise TypeError(f"tz must be string or tzinfo subclass, not {tz!r}.")
# Time-related constants.
EPOCH_OFFSET = float(datetime.datetime(1970, 1, 1).toordinal())
# EPOCH_OFFSET is not used by matplotlib
MICROSECONDLY = SECONDLY + 1
HOURS_PER_DAY = 24.
MIN_PER_HOUR = 60.
SEC_PER_MIN = 60.
MONTHS_PER_YEAR = 12.
DAYS_PER_WEEK = 7.
DAYS_PER_MONTH = 30.
DAYS_PER_YEAR = 365.0
MINUTES_PER_DAY = MIN_PER_HOUR * HOURS_PER_DAY
SEC_PER_HOUR = SEC_PER_MIN * MIN_PER_HOURView on GitHub (pinned to b379c1b69e)
When it happens
Trigger: Thrown at lib/matplotlib/dates.py:224 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of matplotlib/matplotlib@b379c1b69e (2026-08-21).
Data as JSON: /api/errors/9aae22a28f4f3784.
Report an issue: GitHub.