10000 Unclear error message for `plt.xticks(names)` · Issue #12990 · matplotlib/matplotlib · GitHub
[go: up one dir, main page]

Skip to content
Unclear error message for plt.xticks(names) #12990
Closed
@julien-h2

Description

@julien-h2

I suggest to improve the error message when an argument of xticks is missing. This would considerably ease debugging.

from matplotlib import pyplot as plt

xs = [1, 2, 3]
ys = [50, 10, 20]
ticks = ['banana', 'apple', 'pear']
plt.bar(xs, ys)
plt.xticks(ticks)

Here the problem is that I forgot the xs argument for plt.xticks:

plt.xticks(xs, ticks)

The error message should state so, but here's what it currently prints:

AttributeError: 'NoneType' object has no attribute 'update'

And the traceback:

------------------------------------------------------------------
AttributeError                   Traceback (most recent call last)
<ipython-input-80-3ea0d1225cd3> in <module>
     11 plt.bar(xs-width/2, neg_ys, width=width)
     12 plt.bar(xs+width/2, pos_ys, width=width)
---> 13 plt.xticks(ticks)

/usr/local/lib/python3.6/dist-packages/matplotlib/pyplot.py in xticks(ticks, labels, **kwargs)
   1547         labels = ax.get_xticklabels()
   1548     elif labels is None:
-> 1549         locs = ax.set_xticks(ticks)
   1550         labels = ax.get_xticklabels()
   1551     else:

/usr/local/lib/python3.6/dist-packages/matplotlib/axes/_base.py in set_xticks(self, ticks, minor)
   3335             Default is ``False``.
   3336         """
-> 3337         ret = self.xaxis.set_ticks(ticks, minor=minor)
   3338         self.stale = True
   3339         return ret

/usr/local/lib/python3.6/dist-packages/matplotlib/axis.py in set_ticks(self, ticks, minor)
   1702         """
   1703         # XXX if the user changes units, the information will be lost here
-> 1704         ticks = self.convert_units(ticks)
   1705         if len(ticks) > 1:
   1706             xleft, xright = self.get_view_interval()

/usr/local/lib/python3.6/dist-packages/matplotlib/axis.py in convert_units(self, x)
   1528             return x
   1529 
-> 1530         ret = self.converter.convert(x, self.units, self)
   1531         return ret
   1532 

/usr/local/lib/python3.6/dist-packages/matplotlib/category.py in convert(value, unit, axis)
     51 
     52         # force an update so it also does type checking
---> 53         unit.update(values)
     54 
     55         str2idx = np.vectorize(unit._mapping.__getitem__,

AttributeError: 'NoneType' object has no attribute 'update'

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0