matplotlib/matplotlib · error · TypeError

'markevery' list must have all elements of type int

Error message

'markevery' list must have all elements of type int

What it means

validate_markevery() rejects a list markevery whose elements are not all ints. A list form of markevery means 'draw markers exactly at these point indices', so only integers are meaningful; floats, strings, or None inside the list raise this TypeError. This runs when the 'markevery' key of axes.prop_cycle is validated.

Source

Thrown at lib/matplotlib/rcsetup.py:603

    """
    # Validate s against type slice float int and None
    if isinstance(s, (slice, float, int, type(None))):
        return s
    # Validate s against type tuple
    if isinstance(s, tuple):
        if (len(s) == 2
                and (all(isinstance(e, int) for e in s)
                     or all(isinstance(e, float) for e in s))):
            return s
        else:
            raise TypeError(
                "'markevery' tuple must be pair of ints or of floats")
    # Validate s against type list
    if isinstance(s, list):
        if all(isinstance(e, int) for e in s):
            return s
        else:
            raise TypeError(
                "'markevery' list must have all elements of type int")
    raise TypeError("'markevery' is of an invalid type")


validate_markeverylist = _listify_validator(validate_markevery)


def validate_bbox(s):
    if isinstance(s, str):
        s = s.lower()
        if s == 'tight':
            return s
        if s == 'standard':
            return None
        raise ValueError("bbox should be 'tight' or 'standard'")
    elif s is not None:
        # Backwards compatibility. None is equivalent to 'standard'.
        raise ValueError("bbox should be 'tight' or 'standard'")

View on GitHub (pinned to b379c1b69e)

Solutions

  1. Coerce elements to int before use: [int(i) for i in idx_list]
  2. If you meant a range, prefer the tuple form (start, step) instead of enumerating every index
  3. Cast numpy arrays: arr.astype(int).tolist()

Example fix

# before
from cycler import cycler
import matplotlib.pyplot as plt
plt.rc('axes', prop_cycle=cycler(markevery=[[0, 2.0, 4]]))  # 2.0 is float

# after
plt.rc('axes', prop_cycle=cycler(markevery=[[0, 2, 4]]))
Defensive patterns

Strategy: type-guard

Validate before calling

def valid_markevery_list(s):
    return isinstance(s, list) and all(type(e) is int for e in s)

assert valid_markevery_list([0, 2, 4])
assert not valid_markevery_list([0, 2.0, 4])  # 2.0 is float, fails

Type guard

def is_markevery_index_list(v) -> bool:
    return (isinstance(v, list) and len(v) > 0
            and all(isinstance(e, int) and not isinstance(e, bool) for e in v))

Try / catch

try:
    plt.rc('axes', prop_cycle=cycler(markevery=[idx_list]))
except TypeError:
    idx_list = [int(i) for i in idx_list]
    plt.rc('axes', prop_cycle=cycler(markevery=[idx_list]))

Prevention

When it happens

Trigger: cycler(markevery=[[0, 1.5, 3]]) or [[0, '2', 3]] inside a prop_cycle; likewise a bad 'markevery:' line in a style file parsed to a list. Floats that happen to be whole numbers still fail - the check is isinstance-based, not value-based.

Common situations: Loading marker indices from JSON/YAML where the parser produced floats (e.g. 2.0) or numeric strings; reusing an index array from numpy without casting (a numpy int array is not a list of Python ints and fails the earlier list check with the generic type error instead).

Related errors


AI-assisted analysis of matplotlib/matplotlib@b379c1b69e (2026-08-21). Data as JSON: /api/errors/e26d82816c8c1a56. Report an issue: GitHub.