diff --git a/doc/api/next_api_changes/behaviour.rst b/doc/api/next_api_changes/behaviour.rst index 3f93c18b9464..eaf3825a6e0f 100644 --- a/doc/api/next_api_changes/behaviour.rst +++ b/doc/api/next_api_changes/behaviour.rst @@ -41,3 +41,12 @@ did nothing, when passed an unsupported value. It now raises a ``ValueError``. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ``backend_pgf.LatexManager.latex`` is now created with ``encoding="utf-8"``, so its ``stdin``, ``stdout``, and ``stderr`` attributes are utf8-encoded. + +``pyplot.xticks()`` and ``pyplot.yticks()`` +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +Previously, passing labels without passing the ticks to either `.pyplot.xticks` +and `.pyplot.yticks` would result in + + TypeError: object of type 'NoneType' has no len() + +It now raises a ``TypeError`` with a proper description of the error. diff --git a/lib/matplotlib/pyplot.py b/lib/matplotlib/pyplot.py index a10d122c629b..e5769126465f 100644 --- a/lib/matplotlib/pyplot.py +++ b/lib/matplotlib/pyplot.py @@ -1394,14 +1394,17 @@ def xticks(ticks=None, labels=None, **kwargs): """ ax = gca() - if ticks is None and labels is None: + if ticks is None: locs = ax.get_xticks() - labels = ax.get_xticklabels() - elif labels is None: + if labels is not None: + raise TypeError("xticks(): Parameter 'labels' can't be set " + "without setting 'ticks'") + else: locs = ax.set_xticks(ticks) + + if labels is None: labels = ax.get_xticklabels() else: - locs = ax.set_xticks(ticks) labels = ax.set_xticklabels(labels, **kwargs) for l in labels: l.update(kwargs) @@ -1451,14 +1454,17 @@ def yticks(ticks=None, labels=None, **kwargs): """ ax = gca() - if ticks is None and labels is None: + if ticks is None: locs = ax.get_yticks() - labels = ax.get_yticklabels() - elif labels is None: + if labels is not None: + raise TypeError("yticks(): Parameter 'labels' can't be set " + "without setting 'ticks'") + else: locs = ax.set_yticks(ticks) + + if labels is None: labels = ax.get_yticklabels() else: - locs = ax.set_yticks(ticks) labels = ax.set_yticklabels(labels, **kwargs) for l in labels: l.update(kwargs)