Skip to content

Commit 983c579

Browse files
committed
Make MPLPlot plotf stateless
1 parent 3030bba commit 983c579

File tree

1 file changed

+21
-16
lines changed

1 file changed

+21
-16
lines changed

pandas/tools/plotting.py

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -750,6 +750,25 @@ def r(h):
750750
ax.grid()
751751
return ax
752752

753+
def _mplplot_plotf(errorbar=False):
754+
import matplotlib.pyplot as plt
755+
def plotf(ax, x, y, style=None, **kwds):
756+
mask = com.isnull(y)
757+
if mask.any():
758+
y = np.ma.array(y)
759+
y = np.ma.masked_where(mask, y)
760+
761+
if errorbar:
762+
return plt.Axes.errorbar(ax, x, y, **kwds)
763+
else:
764+
# prevent style kwarg from going to errorbar, where it is unsupported
765+
if style is not None:
766+
args = (ax, x, y, style)
767+
else:
768+
args = (ax, x, y)
769+
return plt.Axes.plot(*args, **kwds)
770+
771+
return plotf
753772

754773
class MPLPlot(object):
755774
"""
@@ -1187,22 +1206,8 @@ def _get_plot_function(self):
11871206
the presence of errorbar keywords.
11881207
'''
11891208
errorbar = any(e is not None for e in self.errors.values())
1190-
def plotf(ax, x, y, style=None, **kwds):
1191-
mask = com.isnull(y)
1192-
if mask.any():
1193-
y = np.ma.array(y)
1194-
y = np.ma.masked_where(mask, y)
1195-
1196-
if errorbar:
1197-
return self.plt.Axes.errorbar(ax, x, y, **kwds)
1198-
else:
1199-
# prevent style kwarg from going to errorbar, where it is unsupported
1200-
if style is not None:
1201-
args = (ax, x, y, style)
1202-
else:
1203-
args = (ax, x, y)
1204-
return self.plt.Axes.plot(*args, **kwds)
1205-
return plotf
1209+
1210+
return _mplplot_plotf(errorbar)
12061211

12071212
def _get_index_name(self):
12081213
if isinstance(self.data.index, MultiIndex):

0 commit comments

Comments
 (0)