Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit e521dd9

Browse files
committed
Use warnings.warn, not logging.warning, in microseconds locator warning.
Otherwise something like ``` from pylab import * from matplotlib import dates; from datetime import * plt.plot([datetime(1990, 1, 1), datetime(1990, 1, 1) + timedelta(microseconds=1500)], [0, 0]) plt.show() ``` results in the same warning being emitted multiple times *for every draw* (e.g. when zooming/panning), which is pretty needless spam.
1 parent 0f54425 commit e521dd9

File tree

2 files changed

+14
-5
lines changed

2 files changed

+14
-5
lines changed

lib/matplotlib/dates.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1457,9 +1457,10 @@ def get_locator(self, dmin, dmax):
14571457
else:
14581458
locator = MicrosecondLocator(interval, tz=self.tz)
14591459
if dmin.year > 20 and interval < 1000:
1460-
_log.warning('Plotting microsecond time intervals is not well '
1461-
'supported. Please see the MicrosecondLocator '
1462-
'documentation for details.')
1460+
cbook._warn_external(
1461+
'Plotting microsecond time intervals is not well '
1462+
'supported; please see the MicrosecondLocator '
1463+
'documentation for details.')
14631464

14641465
locator.set_axis(self.axis)
14651466

lib/matplotlib/tests/test_dates.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
import datetime
22
import tempfile
3+
try:
4+
from contextlib import nullcontext
5+
except ImportError:
6+
from contextlib import ExitStack as nullcontext # Py 3.6.
37

48
import dateutil.tz
59
import dateutil.rrule
@@ -371,7 +375,9 @@ def _create_auto_date_locator(date1, date2):
371375
for t_delta, expected in results:
372376
d2 = d1 + t_delta
373377
locator = _create_auto_date_locator(d1, d2)
374-
assert list(map(str, mdates.num2date(locator()))) == expected
378+
with (pytest.warns(UserWarning) if t_delta.microseconds
379+
else nullcontext()):
380+
assert list(map(str, mdates.num2date(locator()))) == expected
375381

376382

377383
def test_auto_date_locator_intmult():
@@ -446,7 +452,9 @@ def _create_auto_date_locator(date1, date2):
446452
for t_delta, expected in results:
447453
d2 = d1 + t_delta
448454
locator = _create_auto_date_locator(d1, d2)
449-
assert list(map(str, mdates.num2date(locator()))) == expected
455+
with (pytest.warns(UserWarning) if t_delta.microseconds
456+
else nullcontext()):
457+
assert list(map(str, mdates.num2date(locator()))) == expected
450458

451459

452460
def test_concise_formatter():

0 commit comments

Comments
 (0)