25
25
26
26
from pandas .core .dtypes .common import (
27
27
is_any_real_numeric_dtype ,
28
+ is_bool ,
28
29
is_float ,
29
30
is_float_dtype ,
30
31
is_hashable ,
@@ -130,7 +131,7 @@ def __init__(
130
131
kind = None ,
131
132
by : IndexLabel | None = None ,
132
133
subplots : bool | Sequence [Sequence [str ]] = False ,
133
- sharex = None ,
134
+ sharex : bool | None = None ,
134
135
sharey : bool = False ,
135
136
use_index : bool = True ,
136
137
figsize : tuple [float , float ] | None = None ,
@@ -191,17 +192,7 @@ def __init__(
191
192
192
193
self .subplots = self ._validate_subplots_kwarg (subplots )
193
194
194
- if sharex is None :
195
- # if by is defined, subplots are used and sharex should be False
196
- if ax is None and by is None :
197
- self .sharex = True
198
- else :
199
- # if we get an axis, the users should do the visibility
200
- # setting...
201
- self .sharex = False
202
- else :
203
- self .sharex = sharex
204
-
195
+ self .sharex = self ._validate_sharex (sharex , ax , by )
205
196
self .sharey = sharey
206
197
self .figsize = figsize
207
198
self .layout = layout
@@ -275,6 +266,20 @@ def __init__(
275
266
276
267
self ._validate_color_args ()
277
268
269
+ @final
270
+ def _validate_sharex (self , sharex : bool | None , ax , by ) -> bool :
271
+ if sharex is None :
272
+ # if by is defined, subplots are used and sharex should be False
273
+ if ax is None and by is None : # pylint: disable=simplifiable-if-statement
274
+ sharex = True
275
+ else :
276
+ # if we get an axis, the users should do the visibility
277
+ # setting...
278
+ sharex = False
279
+ elif not is_bool (sharex ):
280
+ raise TypeError ("sharex must be a bool or None" )
281
+ return bool (sharex )
282
+
278
283
@final
279
284
def _validate_subplots_kwarg (
280
285
self , subplots : bool | Sequence [Sequence [str ]]
@@ -454,7 +459,6 @@ def draw(self) -> None:
454
459
455
460
@final
456
461
def generate (self ) -> None :
457
- self ._args_adjust ()
458
462
self ._compute_plot_data ()
459
463
fig = self ._setup_subplots ()
460
464
self ._make_plot (fig )
@@ -466,10 +470,6 @@ def generate(self) -> None:
466
470
self ._post_plot_logic_common (ax , self .data )
467
471
self ._post_plot_logic (ax , self .data )
468
472
469
- @abstractmethod
470
- def _args_adjust (self ) -> None :
471
- pass
472
-
473
473
@final
474
474
def _has_plotted_object (self , ax : Axes ) -> bool :
475
475
"""check whether ax has data"""
@@ -1326,9 +1326,6 @@ def _make_plot(self, fig: Figure):
1326
1326
err_kwds ["ecolor" ] = scatter .get_facecolor ()[0 ]
1327
1327
ax .errorbar (data [x ].values , data [y ].values , linestyle = "none" , ** err_kwds )
1328
1328
1329
- def _args_adjust (self ) -> None :
1330
- pass
1331
-
1332
1329
1333
1330
class HexBinPlot (PlanePlot ):
1334
1331
@property
@@ -1361,9 +1358,6 @@ def _make_plot(self, fig: Figure) -> None:
1361
1358
def _make_legend (self ) -> None :
1362
1359
pass
1363
1360
1364
- def _args_adjust (self ) -> None :
1365
- pass
1366
-
1367
1361
1368
1362
class LinePlot (MPLPlot ):
1369
1363
_default_rot = 0
@@ -1529,9 +1523,6 @@ def _update_stacker(cls, ax: Axes, stacking_id, values) -> None:
1529
1523
elif (values <= 0 ).all ():
1530
1524
ax ._stacker_neg_prior [stacking_id ] += values
1531
1525
1532
- def _args_adjust (self ) -> None :
1533
- pass
1534
-
1535
1526
def _post_plot_logic (self , ax : Axes , data ) -> None :
1536
1527
from matplotlib .ticker import FixedLocator
1537
1528
@@ -1641,9 +1632,6 @@ def _plot( # type: ignore[override]
1641
1632
res = [rect ]
1642
1633
return res
1643
1634
1644
- def _args_adjust (self ) -> None :
1645
- pass
1646
-
1647
1635
def _post_plot_logic (self , ax : Axes , data ) -> None :
1648
1636
LinePlot ._post_plot_logic (self , ax , data )
1649
1637
@@ -1676,8 +1664,14 @@ def __init__(self, data, **kwargs) -> None:
1676
1664
kwargs .setdefault ("align" , "center" )
1677
1665
self .tick_pos = np .arange (len (data ))
1678
1666
1679
- self .bottom = kwargs .pop ("bottom" , 0 )
1680
- self .left = kwargs .pop ("left" , 0 )
1667
+ bottom = kwargs .pop ("bottom" , 0 )
1668
+ left = kwargs .pop ("left" , 0 )
1669
+ if is_list_like (bottom ):
1670
+ bottom = np .array (bottom )
1671
+ if is_list_like (left ):
1672
+ left = np .array (left )
1673
+ self .bottom = bottom
1674
+ self .left = left
1681
1675
1682
1676
self .log = kwargs .pop ("log" , False )
1683
1677
MPLPlot .__init__ (self , data , ** kwargs )
@@ -1698,12 +1692,6 @@ def __init__(self, data, **kwargs) -> None:
1698
1692
1699
1693
self .ax_pos = self .tick_pos - self .tickoffset
1700
1694
1701
- def _args_adjust (self ) -> None :
1702
- if is_list_like (self .bottom ):
1703
- self .bottom = np .array (self .bottom )
1704
- if is_list_like (self .left ):
1705
- self .left = np .array (self .left )
1706
-
1707
1695
# error: Signature of "_plot" incompatible with supertype "MPLPlot"
1708
1696
@classmethod
1709
1697
def _plot ( # type: ignore[override]
@@ -1874,8 +1862,6 @@ def __init__(self, data, kind=None, **kwargs) -> None:
1874
1862
if (data < 0 ).any ().any ():
1875
1863
raise ValueError (f"{ self ._kind } plot doesn't allow negative values" )
1876
1864
MPLPlot .__init__ (self , data , kind = kind , ** kwargs )
1877
-
1878
- def _args_adjust (self ) -> None :
1879
1865
self .grid = False
1880
1866
self .logy = False
1881
1867
self .logx = False
0 commit comments