diff --git a/lib/matplotlib/axis.py b/lib/matplotlib/axis.py index 18d54b658ea9..886a544251cc 100644 --- a/lib/matplotlib/axis.py +++ b/lib/matplotlib/axis.py @@ -1434,6 +1434,13 @@ def update_units(self, data): if converter is None: return False + if (self.converter is not None) and (self.converter != converter): + raise TypeError('Attempting to plot data that is ' + 'registered to be converted with %s but ' + 'is incompatible with existing axis data ' + 'converter %s' % (converter.__class__, + self.converter.__class__)) + neednew = self.converter != converter self.converter = converter default = self.converter.default_units(data, self) diff --git a/lib/matplotlib/tests/test_dates.py b/lib/matplotlib/tests/test_dates.py index 437482f5fa2e..e457532fd4aa 100644 --- a/lib/matplotlib/tests/test_dates.py +++ b/lib/matplotlib/tests/test_dates.py @@ -477,3 +477,14 @@ def test_tz_utc(): def test_num2timedelta(x, tdelta): dt = mdates.num2timedelta(x) assert dt == tdelta + + +def test_one_non_None_converter(): + # test that we only allow one non-None converter at once: + base = datetime.datetime(2017, 1, 1, 0, 10, 0) + time = [base - datetime.timedelta(days=x) for x in range(0, 3)] + data = [0., 2., 4.] + fig, ax = plt.subplots() + ax.plot(time, data) + with pytest.raises(TypeError): + ax.plot(['a', 'b'], [1., 2.])