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

Skip to content

Commit d104c74

Browse files
committed
Lazy import of private modules
1 parent 006468b commit d104c74

File tree

5 files changed

+15
-8
lines changed

5 files changed

+15
-8
lines changed

lib/matplotlib/backends/backend_agg.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@
3838
from matplotlib import colors as mcolors
3939

4040
from matplotlib.backends._backend_agg import RendererAgg as _RendererAgg
41-
from matplotlib import _png
4241

4342
from matplotlib.backend_bases import _has_pil
4443

@@ -502,6 +501,8 @@ def print_png(self, filename_or_obj, *args, **kwargs):
502501
https://www.w3.org/TR/2003/REC-PNG-20031110/#11keywords
503502
504503
"""
504+
from matplotlib import _png
505+
505506
FigureCanvasAgg.draw(self)
506507
renderer = self.get_renderer()
507508

lib/matplotlib/contour.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
from numpy import ma
99

1010
import matplotlib as mpl
11-
import matplotlib._contour as _contour
1211
import matplotlib.path as mpath
1312
import matplotlib.ticker as ticker
1413
import matplotlib.cm as cm
@@ -1481,6 +1480,8 @@ def _process_args(self, *args, **kwargs):
14811480
self._mins = args[0]._mins
14821481
self._maxs = args[0]._maxs
14831482
else:
1483+
import matplotlib._contour as contour
1484+
14841485
self._corner_mask = kwargs.pop('corner_mask', None)
14851486
if self._corner_mask is None:
14861487
self._corner_mask = mpl.rcParams['contour.corner_mask']

lib/matplotlib/image.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121

2222
# For clarity, names from _image are given explicitly in this module:
2323
import matplotlib._image as _image
24-
import matplotlib._png as _png
2524

2625
# For user convenience, the names from _image are also imported into
2726
# the image namespace:
@@ -613,6 +612,7 @@ def contains(self, mouseevent):
613612

614613
def write_png(self, fname):
615614
"""Write the image to png file with fname"""
615+
from matplotlib import _png
616616
im = self.to_rgba(self._A[::-1] if self.origin == 'lower' else self._A,
617617
bytes=True, norm=True)
618618
_png.write_png(im, fname)
@@ -1340,7 +1340,11 @@ def imread(fname, format=None):
13401340
.. _Pillow documentation: http://pillow.readthedocs.io/en/latest/
13411341
"""
13421342

1343-
handlers = {'png': _png.read_png, }
1343+
def read_png(*args, **kwargs):
1344+
from matplotlib import _png
1345+
return _png.read_png(*args, **kwargs)
1346+
1347+
handlers = {'png': read_png, }
13441348
if format is None:
13451349
if isinstance(fname, str):
13461350
parsed = urllib.parse.urlparse(fname)

lib/matplotlib/mathtext.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131

3232
ParserElement.enablePackrat()
3333

34-
from matplotlib import _png, cbook, colors as mcolors, get_data_path, rcParams
34+
from matplotlib import cbook, colors as mcolors, get_data_path, rcParams
3535
from matplotlib.afm import AFM
3636
from matplotlib.cbook import get_realpath_and_stat
3737
from matplotlib.ft2font import FT2Image, KERNING_DEFAULT, LOAD_NO_HINTING
@@ -3446,6 +3446,7 @@ def to_png(self, filename, texstr, color='black', dpi=120, fontsize=14):
34463446
Returns the offset of the baseline from the bottom of the
34473447
image in pixels.
34483448
"""
3449+
from matplotlib import _png
34493450
rgba, depth = self.to_rgba(
34503451
texstr, color=color, dpi=dpi, fontsize=fontsize)
34513452
_png.write_png(rgba, filename)

lib/matplotlib/tri/triangulation.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
import numpy as np
22

3-
import matplotlib._tri as _tri
4-
import matplotlib._qhull as _qhull
5-
63

74
class Triangulation(object):
85
"""
@@ -39,6 +36,8 @@ class Triangulation(object):
3936
triangles formed from colinear points, or overlapping triangles.
4037
"""
4138
def __init__(self, x, y, triangles=None, mask=None):
39+
from matplotlib import _qhull
40+
4241
self.x = np.asarray(x, dtype=np.float64)
4342
self.y = np.asarray(y, dtype=np.float64)
4443
if self.x.shape != self.y.shape or self.x.ndim != 1:
@@ -106,6 +105,7 @@ def get_cpp_triangulation(self):
106105
Return the underlying C++ Triangulation object, creating it
107106
if necessary.
108107
"""
108+
from matplotlib import _tri
109109
if self._cpp_triangulation is None:
110110
self._cpp_triangulation = _tri.Triangulation(
111111
self.x, self.y, self.triangles, self.mask, self._edges,

0 commit comments

Comments
 (0)