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