Skip to content

Commit 28aaecf

Browse files
committed
delay pyplot import
1 parent d03a41d commit 28aaecf

File tree

7 files changed

+19
-9
lines changed

7 files changed

+19
-9
lines changed

pandas/plotting/_matplotlib/boxplot.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
from collections import namedtuple
22
import warnings
33

4-
from matplotlib import pyplot as plt
54
from matplotlib.artist import setp
65
import numpy as np
76

@@ -216,6 +215,7 @@ def boxplot(data, column=None, by=None, ax=None, fontsize=None,
216215
rot=0, grid=True, figsize=None, layout=None, return_type=None,
217216
**kwds):
218217

218+
import matplotlib.pyplot as plt
219219
# validate return_type:
220220
if return_type not in BoxPlot._valid_return_types:
221221
raise ValueError("return_type must be {'axes', 'dict', 'both'}")
@@ -297,6 +297,7 @@ def plot_group(keys, values, ax):
297297
def boxplot_frame(self, column=None, by=None, ax=None, fontsize=None, rot=0,
298298
grid=True, figsize=None, layout=None,
299299
return_type=None, **kwds):
300+
import matplotlib.pyplot as plt
300301
converter._WARN = False # no warning for pandas plots
301302
ax = boxplot(self, column=column, by=by, ax=ax, fontsize=fontsize,
302303
grid=grid, rot=rot, figsize=figsize, layout=layout,

pandas/plotting/_matplotlib/core.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
from typing import Optional # noqa
33
import warnings
44

5-
import matplotlib.pyplot as plt
65
import numpy as np
76

87
from pandas._config import get_option
@@ -61,6 +60,7 @@ def __init__(self, data, kind=None, by=None, subplots=False, sharex=None,
6160
secondary_y=False, colormap=None,
6261
table=False, layout=None, **kwds):
6362

63+
import matplotlib.pyplot as plt
6464
converter._WARN = False # no warning for pandas plots
6565
self.data = data
6666
self.by = by
@@ -104,7 +104,7 @@ def __init__(self, data, kind=None, by=None, subplots=False, sharex=None,
104104
self.rot = self._default_rot
105105

106106
if grid is None:
107-
grid = False if secondary_y else self.plt.rcParams['axes.grid']
107+
grid = False if secondary_y else plt.rcParams['axes.grid']
108108

109109
self.grid = grid
110110
self.legend = legend
@@ -619,6 +619,8 @@ def _get_ax(self, i):
619619

620620
@classmethod
621621
def get_default_ax(cls, ax):
622+
import matplotlib.pyplot as plt
623+
622624
if ax is None and len(plt.get_fignums()) > 0:
623625
with plt.rc_context():
624626
ax = plt.gca()

pandas/plotting/_matplotlib/hist.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import warnings
22

3-
import matplotlib.pyplot as plt
43
import numpy as np
54

65
from pandas.core.dtypes.common import is_integer, is_list_like
@@ -222,6 +221,7 @@ def plot_group(group, ax):
222221
def hist_series(self, by=None, ax=None, grid=True, xlabelsize=None,
223222
xrot=None, ylabelsize=None, yrot=None, figsize=None,
224223
bins=10, **kwds):
224+
import matplotlib.pyplot as plt
225225
if by is None:
226226
if kwds.get('layout', None) is not None:
227227
raise ValueError("The 'layout' keyword is not supported when "

pandas/plotting/_matplotlib/misc.py

+7-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
import matplotlib.lines as mlines
44
import matplotlib.patches as patches
5-
import matplotlib.pyplot as plt
65
import numpy as np
76

87
from pandas.core.dtypes.missing import notna
@@ -105,6 +104,7 @@ def _get_marker_compat(marker):
105104

106105

107106
def radviz(frame, class_column, ax=None, color=None, colormap=None, **kwds):
107+
import matplotlib.pyplot as plt
108108

109109
def normalize(series):
110110
a = min(series)
@@ -169,6 +169,7 @@ def normalize(series):
169169

170170
def andrews_curves(frame, class_column, ax=None, samples=200, color=None,
171171
colormap=None, **kwds):
172+
import matplotlib.pyplot as plt
172173

173174
def function(amplitudes):
174175
def f(t):
@@ -224,6 +225,7 @@ def f(t):
224225

225226
def bootstrap_plot(series, fig=None, size=50, samples=500, **kwds):
226227

228+
import matplotlib.pyplot as plt
227229
# random.sample(ndarray, int) fails on python 3.3, sigh
228230
data = list(series.values)
229231
samplings = [random.sample(data, size) for _ in range(samples)]
@@ -270,6 +272,7 @@ def parallel_coordinates(frame, class_column, cols=None, ax=None, color=None,
270272
use_columns=False, xticks=None, colormap=None,
271273
axvlines=True, axvlines_kwds=None, sort_labels=False,
272274
**kwds):
275+
import matplotlib.pyplot as plt
273276
if axvlines_kwds is None:
274277
axvlines_kwds = {'linewidth': 1, 'color': 'black'}
275278

@@ -336,6 +339,7 @@ def parallel_coordinates(frame, class_column, cols=None, ax=None, color=None,
336339

337340
def lag_plot(series, lag=1, ax=None, **kwds):
338341
# workaround because `c='b'` is hardcoded in matplotlibs scatter method
342+
import matplotlib.pyplot as plt
339343
kwds.setdefault('c', plt.rcParams['patch.facecolor'])
340344

341345
data = series.values
@@ -350,6 +354,8 @@ def lag_plot(series, lag=1, ax=None, **kwds):
350354

351355

352356
def autocorrelation_plot(series, ax=None, **kwds):
357+
import matplotlib.pyplot as plt
358+
353359
n = len(series)
354360
data = np.asarray(series)
355361
if ax is None:

pandas/plotting/_matplotlib/style.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33

44
import matplotlib.cm as cm
55
import matplotlib.colors
6-
import matplotlib.pyplot as plt
76
import numpy as np
87

98
from pandas.core.dtypes.common import is_list_like
@@ -13,6 +12,7 @@
1312

1413
def _get_standard_colors(num_colors=None, colormap=None, color_type='default',
1514
color=None):
15+
import matplotlib.pyplot as plt
1616
if color is None and colormap is not None:
1717
if isinstance(colormap, str):
1818
cmap = colormap

pandas/plotting/_matplotlib/timeseries.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33
import functools
44
import warnings
55

6-
from matplotlib import pylab
7-
import matplotlib.pyplot as plt
86
import numpy as np
97

108
from pandas._libs.tslibs.frequencies import (
@@ -42,6 +40,7 @@ def tsplot(series, plotf, ax=None, **kwargs):
4240
.. deprecated:: 0.23.0
4341
Use Series.plot() instead
4442
"""
43+
import matplotlib.pyplot as plt
4544
warnings.warn("'tsplot' is deprecated and will be removed in a "
4645
"future version. Please use Series.plot() instead.",
4746
FutureWarning, stacklevel=2)
@@ -323,6 +322,7 @@ def format_dateaxis(subplot, freq, index):
323322
default, changing the limits of the x axis will intelligently change
324323
the positions of the ticks.
325324
"""
325+
from matplotlib import pylab
326326

327327
# handle index specific formatting
328328
# Note: DatetimeIndex does not use this

pandas/plotting/_matplotlib/tools.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
from math import ceil
33
import warnings
44

5-
import matplotlib.pyplot as plt
65
import matplotlib.table
76
import matplotlib.ticker as ticker
87
import numpy as np
@@ -168,6 +167,7 @@ def _subplots(naxes=None, sharex=False, sharey=False, squeeze=True,
168167
# Four polar axes
169168
plt.subplots(2, 2, subplot_kw=dict(polar=True))
170169
"""
170+
import matplotlib.pyplot as plt
171171
if subplot_kw is None:
172172
subplot_kw = {}
173173

@@ -345,6 +345,7 @@ def _get_xlim(lines):
345345

346346
def _set_ticks_props(axes, xlabelsize=None, xrot=None,
347347
ylabelsize=None, yrot=None):
348+
import matplotlib.pyplot as plt
348349
for ax in _flatten(axes):
349350
if xlabelsize is not None:
350351
plt.setp(ax.get_xticklabels(), fontsize=xlabelsize)

0 commit comments

Comments
 (0)