@@ -865,7 +865,7 @@ def _get_call_args(backend_name, data, args, kwargs):
865
865
if args and isinstance (data , ABCSeries ):
866
866
positional_args = str (args )[1 :- 1 ]
867
867
keyword_args = ", " .join (
868
- f"{ name } ={ repr (value )} " for (name , default ), value in zip (arg_def , args )
868
+ f"{ name } ={ repr (value )} " for (name , _ ), value in zip (arg_def , args )
869
869
)
870
870
msg = (
871
871
"`Series.plot()` should not be called with positional "
@@ -876,7 +876,7 @@ def _get_call_args(backend_name, data, args, kwargs):
876
876
)
877
877
raise TypeError (msg )
878
878
879
- pos_args = {name : value for value , (name , _ ) in zip (args , arg_def )}
879
+ pos_args = {name : value for (name , _ ), value in zip (arg_def , args )}
880
880
if backend_name == "pandas.plotting._matplotlib" :
881
881
kwargs = dict (arg_def , ** pos_args , ** kwargs )
882
882
else :
@@ -1729,7 +1729,7 @@ def hexbin(self, x, y, C=None, reduce_C_function=None, gridsize=None, **kwargs):
1729
1729
1730
1730
def _find_backend (backend : str ):
1731
1731
"""
1732
- Find a pandas plotting backend>
1732
+ Find a pandas plotting backend.
1733
1733
1734
1734
Parameters
1735
1735
----------
@@ -1749,11 +1749,8 @@ def _find_backend(backend: str):
1749
1749
import pkg_resources # Delay import for performance.
1750
1750
1751
1751
for entry_point in pkg_resources .iter_entry_points ("pandas_plotting_backends" ):
1752
- if entry_point .name == "matplotlib" :
1753
- # matplotlib is an optional dependency. When
1754
- # missing, this would raise.
1755
- continue
1756
- _backends [entry_point .name ] = entry_point .load ()
1752
+ if entry_point .name == backend :
1753
+ _backends [entry_point .name ] = entry_point .load ()
1757
1754
1758
1755
try :
1759
1756
return _backends [backend ]
@@ -1778,21 +1775,26 @@ def _find_backend(backend: str):
1778
1775
)
1779
1776
1780
1777
1781
- def _get_plot_backend (backend = None ):
1778
+ def _get_plot_backend (backend : str | None = None ):
1782
1779
"""
1783
1780
Return the plotting backend to use (e.g. `pandas.plotting._matplotlib`).
1784
1781
1785
- The plotting system of pandas has been using matplotlib, but the idea here
1786
- is that it can also work with other third-party backends. In the future,
1787
- this function will return the backend from a pandas option, and all the
1788
- rest of the code in this file will use the backend specified there for the
1789
- plotting.
1782
+ The plotting system of pandas uses matplotlib by default, but the idea here
1783
+ is that it can also work with other third-party backends. This function
1784
+ returns the module which provides a top-level `.plot` method that will
1785
+ actually do the plotting. The backend is specified from a string, which
1786
+ either comes from the keyword argument `backend`, or, if not specified, from
1787
+ the option `pandas.options.plotting.backend`. All the rest of the code in
1788
+ this file uses the backend specified there for the plotting.
1790
1789
1791
1790
The backend is imported lazily, as matplotlib is a soft dependency, and
1792
1791
pandas can be used without it being installed.
1793
1792
"""
1794
1793
backend = backend or get_option ("plotting.backend" )
1795
1794
1795
+ if backend in _backends :
1796
+ return _backends [backend ]
1797
+
1796
1798
if backend == "matplotlib" :
1797
1799
# Because matplotlib is an optional dependency and first-party backend,
1798
1800
# we need to attempt an import here to raise an ImportError if needed.
@@ -1805,10 +1807,7 @@ def _get_plot_backend(backend=None):
1805
1807
) from None
1806
1808
1807
1809
_backends ["matplotlib" ] = module
1808
-
1809
- if backend in _backends :
1810
- return _backends [backend ]
1810
+ return module
1811
1811
1812
1812
module = _find_backend (backend )
1813
- _backends [backend ] = module
1814
1813
return module
0 commit comments