|
1 | 1 | """
|
2 |
| -A collection of utility functions and classes. Many (but not all) |
3 |
| -from the Python Cookbook -- hence the name cbook |
| 2 | +A collection of utility functions and classes. Originally, many |
| 3 | +(but not all) were from the Python Cookbook -- hence the name cbook. |
| 4 | +
|
| 5 | +This module is safe to import from anywhere within matplotlib; |
| 6 | +it imports matplotlib only at runtime. |
4 | 7 | """
|
| 8 | + |
5 | 9 | from __future__ import print_function
|
6 | 10 |
|
7 | 11 | import datetime
|
|
18 | 22 | import threading
|
19 | 23 | import time
|
20 | 24 | import traceback
|
| 25 | +import types |
21 | 26 | import warnings
|
22 | 27 | from weakref import ref, WeakKeyDictionary
|
23 | 28 |
|
24 |
| -import matplotlib |
25 |
| -from matplotlib import MatplotlibDeprecationWarning as mplDeprecation |
26 |
| - |
27 | 29 | import numpy as np
|
28 | 30 | import numpy.ma as ma
|
29 | 31 |
|
30 | 32 |
|
31 |
| -import types |
| 33 | +class MatplotlibDeprecationWarning(UserWarning): |
| 34 | + """ |
| 35 | + A class for issuing deprecation warnings for Matplotlib users. |
32 | 36 |
|
| 37 | + In light of the fact that Python builtin DeprecationWarnings are ignored |
| 38 | + by default as of Python 2.7 (see link below), this class was put in to |
| 39 | + allow for the signaling of deprecation, but via UserWarnings which are not |
| 40 | + ignored by default. |
| 41 | +
|
| 42 | + http://docs.python.org/dev/whatsnew/2.7.html#the-future-for-python-2-x |
| 43 | + """ |
| 44 | + pass |
| 45 | + |
| 46 | +mplDeprecation = MatplotlibDeprecationWarning |
33 | 47 |
|
34 | 48 | # On some systems, locale.getpreferredencoding returns None,
|
35 | 49 | # which can break unicode; and the sage project reports that
|
|
42 | 56 |
|
43 | 57 | if sys.version_info[0] >= 3:
|
44 | 58 | def unicode_safe(s):
|
| 59 | + import matplotlib |
| 60 | + |
45 | 61 | try:
|
46 | 62 | preferredencoding = locale.getpreferredencoding(
|
47 | 63 | matplotlib.rcParams['axes.formatter.use_locale']).strip()
|
@@ -576,6 +592,8 @@ def get_sample_data(fname, asfileobj=True):
|
576 | 592 |
|
577 | 593 | If the filename ends in .gz, the file is implicitly ungzipped.
|
578 | 594 | """
|
| 595 | + import matplotlib |
| 596 | + |
579 | 597 | if matplotlib.rcParams['examples.directory']:
|
580 | 598 | root = matplotlib.rcParams['examples.directory']
|
581 | 599 | else:
|
|
0 commit comments