Skip to content

Commit f1b9fc1

Browse files
datapythonistaTomAugspurger
authored andcommitted
PLT: Delegating to plotting backend only plots of Series and DataFrame methods (#27432)
1 parent c50b0e7 commit f1b9fc1

File tree

2 files changed

+14
-14
lines changed

2 files changed

+14
-14
lines changed

pandas/plotting/_core.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -375,7 +375,7 @@ def boxplot(
375375
>>> type(boxplot)
376376
<class 'numpy.ndarray'>
377377
"""
378-
plot_backend = _get_plot_backend()
378+
plot_backend = _get_plot_backend("matplotlib")
379379
return plot_backend.boxplot(
380380
data,
381381
column=column,
@@ -1533,7 +1533,7 @@ def hexbin(self, x, y, C=None, reduce_C_function=None, gridsize=None, **kwargs):
15331533
return self(kind="hexbin", x=x, y=y, C=C, **kwargs)
15341534

15351535

1536-
def _get_plot_backend():
1536+
def _get_plot_backend(backend=None):
15371537
"""
15381538
Return the plotting backend to use (e.g. `pandas.plotting._matplotlib`).
15391539
@@ -1546,7 +1546,7 @@ def _get_plot_backend():
15461546
The backend is imported lazily, as matplotlib is a soft dependency, and
15471547
pandas can be used without it being installed.
15481548
"""
1549-
backend_str = pandas.get_option("plotting.backend")
1549+
backend_str = backend or pandas.get_option("plotting.backend")
15501550
if backend_str == "matplotlib":
15511551
backend_str = "pandas.plotting._matplotlib"
15521552
return importlib.import_module(backend_str)

pandas/plotting/_misc.py

+11-11
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ def table(ax, data, rowLabels=None, colLabels=None, **kwargs):
2424
-------
2525
matplotlib table object
2626
"""
27-
plot_backend = _get_plot_backend()
27+
plot_backend = _get_plot_backend("matplotlib")
2828
return plot_backend.table(
2929
ax=ax, data=data, rowLabels=None, colLabels=None, **kwargs
3030
)
@@ -48,7 +48,7 @@ def register(explicit=True):
4848
--------
4949
deregister_matplotlib_converter
5050
"""
51-
plot_backend = _get_plot_backend()
51+
plot_backend = _get_plot_backend("matplotlib")
5252
plot_backend.register(explicit=explicit)
5353

5454

@@ -67,7 +67,7 @@ def deregister():
6767
--------
6868
deregister_matplotlib_converters
6969
"""
70-
plot_backend = _get_plot_backend()
70+
plot_backend = _get_plot_backend("matplotlib")
7171
plot_backend.deregister()
7272

7373

@@ -124,7 +124,7 @@ def scatter_matrix(
124124
>>> df = pd.DataFrame(np.random.randn(1000, 4), columns=['A','B','C','D'])
125125
>>> scatter_matrix(df, alpha=0.2)
126126
"""
127-
plot_backend = _get_plot_backend()
127+
plot_backend = _get_plot_backend("matplotlib")
128128
return plot_backend.scatter_matrix(
129129
frame=frame,
130130
alpha=alpha,
@@ -202,7 +202,7 @@ def radviz(frame, class_column, ax=None, color=None, colormap=None, **kwds):
202202
... })
203203
>>> rad_viz = pd.plotting.radviz(df, 'Category') # doctest: +SKIP
204204
"""
205-
plot_backend = _get_plot_backend()
205+
plot_backend = _get_plot_backend("matplotlib")
206206
return plot_backend.radviz(
207207
frame=frame,
208208
class_column=class_column,
@@ -249,7 +249,7 @@ def andrews_curves(
249249
-------
250250
class:`matplotlip.axis.Axes`
251251
"""
252-
plot_backend = _get_plot_backend()
252+
plot_backend = _get_plot_backend("matplotlib")
253253
return plot_backend.andrews_curves(
254254
frame=frame,
255255
class_column=class_column,
@@ -307,7 +307,7 @@ def bootstrap_plot(series, fig=None, size=50, samples=500, **kwds):
307307
>>> s = pd.Series(np.random.uniform(size=100))
308308
>>> fig = pd.plotting.bootstrap_plot(s) # doctest: +SKIP
309309
"""
310-
plot_backend = _get_plot_backend()
310+
plot_backend = _get_plot_backend("matplotlib")
311311
return plot_backend.bootstrap_plot(
312312
series=series, fig=fig, size=size, samples=samples, **kwds
313313
)
@@ -374,7 +374,7 @@ def parallel_coordinates(
374374
color=('#556270', '#4ECDC4', '#C7F464'))
375375
>>> plt.show()
376376
"""
377-
plot_backend = _get_plot_backend()
377+
plot_backend = _get_plot_backend("matplotlib")
378378
return plot_backend.parallel_coordinates(
379379
frame=frame,
380380
class_column=class_column,
@@ -405,7 +405,7 @@ def lag_plot(series, lag=1, ax=None, **kwds):
405405
-------
406406
class:`matplotlib.axis.Axes`
407407
"""
408-
plot_backend = _get_plot_backend()
408+
plot_backend = _get_plot_backend("matplotlib")
409409
return plot_backend.lag_plot(series=series, lag=lag, ax=ax, **kwds)
410410

411411

@@ -424,7 +424,7 @@ def autocorrelation_plot(series, ax=None, **kwds):
424424
-------
425425
class:`matplotlib.axis.Axes`
426426
"""
427-
plot_backend = _get_plot_backend()
427+
plot_backend = _get_plot_backend("matplotlib")
428428
return plot_backend.autocorrelation_plot(series=series, ax=ax, **kwds)
429429

430430

@@ -451,7 +451,7 @@ def tsplot(series, plotf, ax=None, **kwargs):
451451
FutureWarning,
452452
stacklevel=2,
453453
)
454-
plot_backend = _get_plot_backend()
454+
plot_backend = _get_plot_backend("matplotlib")
455455
return plot_backend.tsplot(series=series, plotf=plotf, ax=ax, **kwargs)
456456

457457

0 commit comments

Comments
 (0)