18
18
except ImportError :
19
19
pass
20
20
21
+ _shared_docs = """figsize : a tuple (width, height) in inches
22
+ subplots : boolean, default False
23
+ Make separate subplots for each column
24
+ sharex : boolean, default True if ax is None else False
25
+ In case subplots=True, share x axis and set some x axis labels to invisible;
26
+ defaults to True if ax is None otherwise False if an ax is passed in;
27
+ Be aware, that passing in both an ax and sharex=True will alter all x axis
28
+ labels for all axis in a figure!
29
+ sharey : boolean, default False
30
+ In case subplots=True, share y axis and set some y axis labels to subplots
31
+ layout : tuple (optional)
32
+ (rows, columns) for the layout of subplots
33
+ title : string or list
34
+ Title to use for the plot. If a string is passed, print the string at the
35
+ top of the figure. If a list is passed and subplots is True, print each item
36
+ in the list above the corresponding subplot.
37
+ """
21
38
22
39
def hist_series (
23
40
self ,
@@ -588,7 +605,7 @@ class PlotAccessor(PandasObject):
588
605
labels with "(right)" in the legend
589
606
include_bool : bool, default is False
590
607
If True, boolean values can be plotted.
591
- `**kwds ` : keywords
608
+ `**kwargs ` : keywords
592
609
Options to pass to matplotlib plotting method.
593
610
594
611
Returns
@@ -795,8 +812,7 @@ def __call__(self, *args, **kwargs):
795
812
796
813
return plot_backend .plot (data , kind = kind , ** kwargs )
797
814
798
- def line (self , x = None , y = None , ** kwargs ):
799
- """
815
+ line_docs = """
800
816
Plot Series or DataFrame as lines.
801
817
802
818
This function is useful to plot lines using DataFrame's values
@@ -812,7 +828,8 @@ def line(self, x=None, y=None, **kwargs):
812
828
The values to be plotted.
813
829
Either the location or the label of the columns to be used.
814
830
By default, it will use the remaining DataFrame numeric columns.
815
- **kwds
831
+ %s
832
+ **kwargs
816
833
Keyword arguments to pass on to :meth:`DataFrame.plot`.
817
834
818
835
Returns
@@ -862,9 +879,14 @@ def line(self, x=None, y=None, **kwargs):
862
879
863
880
>>> lines = df.plot.line(x='pig', y='horse')
864
881
"""
865
- return self (kind = "line" , x = x , y = y , ** kwargs )
866
-
867
- def bar (self , x = None , y = None , ** kwargs ):
882
+ @Appender (_line_docs % _shared_docs )
883
+ def line (self , x = None , y = None , figsize = None , subplots = False , sharex = None ,
884
+ sharey = False , layout = None , title = None , ** kwargs ):
885
+ return self (kind = "line" , x = x , y = y , figsize = figsize , subplots = subplots ,
886
+ sharex = sharex , sharey = sharey , layout = layout , title = title , ** kwargs )
887
+
888
+ def bar (self , x = None , y = None , figsize = None , subplots = False , sharex = None ,
889
+ sharey = False , layout = None , title = None , ** kwargs ):
868
890
"""
869
891
Vertical bar plot.
870
892
@@ -882,7 +904,8 @@ def bar(self, x=None, y=None, **kwargs):
882
904
y : label or position, optional
883
905
Allows plotting of one column versus another. If not specified,
884
906
all numerical columns are used.
885
- **kwds
907
+ %s
908
+ **kwargs
886
909
Additional keyword arguments are documented in
887
910
:meth:`DataFrame.plot`.
888
911
@@ -947,10 +970,10 @@ def bar(self, x=None, y=None, **kwargs):
947
970
948
971
>>> ax = df.plot.bar(x='lifespan', rot=0)
949
972
"""
950
- return self (kind = "bar" , x = x , y = y , ** kwargs )
973
+ return self (kind = "bar" , x = x , y = y , figsize = figsize , subplots = subplots ,
974
+ sharex = sharex , sharey = sharey , layout = layout , title = title , ** kwargs )
951
975
952
- def barh (self , x = None , y = None , ** kwargs ):
953
- """
976
+ _barh_docs = """
954
977
Make a horizontal bar plot.
955
978
956
979
A horizontal bar plot is a plot that presents quantitative data with
@@ -965,7 +988,8 @@ def barh(self, x=None, y=None, **kwargs):
965
988
Column to be used for categories.
966
989
y : label or position, default All numeric columns in dataframe
967
990
Columns to be plotted from the DataFrame.
968
- **kwds
991
+ %s
992
+ **kwargs
969
993
Keyword arguments to pass on to :meth:`DataFrame.plot`.
970
994
971
995
Returns
@@ -1026,11 +1050,14 @@ def barh(self, x=None, y=None, **kwargs):
1026
1050
>>> df = pd.DataFrame({'speed': speed,
1027
1051
... 'lifespan': lifespan}, index=index)
1028
1052
>>> ax = df.plot.barh(x='lifespan')
1029
- """
1030
- return self (kind = "barh" , x = x , y = y , ** kwargs )
1053
+ """
1054
+ @Appender (_barh_docs % shared_docs )
1055
+ def barh (self , x = None , y = None , figsize = None , subplots = False , sharex = None ,
1056
+ sharey = False , layout = None , title = None , ** kwargs ):
1057
+ return self (kind = "barh" , x = x , y = y , figsize = figsize , subplots = subplots ,
1058
+ sharex = sharex , sharey = sharey , layout = layout , title = title , ** kwargs )
1031
1059
1032
- def box (self , by = None , ** kwargs ):
1033
- r"""
1060
+ _box_docs = r"""
1034
1061
Make a box plot of the DataFrame columns.
1035
1062
1036
1063
A box plot is a method for graphically depicting groups of numerical
@@ -1051,7 +1078,8 @@ def box(self, by=None, **kwargs):
1051
1078
----------
1052
1079
by : str or sequence
1053
1080
Column in the DataFrame to group by.
1054
- **kwds : optional
1081
+ %s
1082
+ **kwargs : optional
1055
1083
Additional keywords are documented in
1056
1084
:meth:`DataFrame.plot`.
1057
1085
@@ -1077,10 +1105,14 @@ def box(self, by=None, **kwargs):
1077
1105
>>> df = pd.DataFrame(data, columns=list('ABCD'))
1078
1106
>>> ax = df.plot.box()
1079
1107
"""
1080
- return self (kind = "box" , by = by , ** kwargs )
1081
1108
1082
- def hist (self , by = None , bins = 10 , ** kwargs ):
1083
- """
1109
+ @Appender (_box_docs % _shared_docs )
1110
+ def box (self , by = None , figsize = None , subplots = False , sharex = None , sharey = False ,
1111
+ layout = None , title = None , ** kwargs ):
1112
+ return self (kind = "box" , by = by , figsize = figsize , subplots = subplots ,
1113
+ sharex = sharex , sharey = sharey , layout = layout , title = title , ** kwargs )
1114
+
1115
+ _hist_docs = """
1084
1116
Draw one histogram of the DataFrame's columns.
1085
1117
1086
1118
A histogram is a representation of the distribution of data.
@@ -1094,7 +1126,8 @@ def hist(self, by=None, bins=10, **kwargs):
1094
1126
Column in the DataFrame to group by.
1095
1127
bins : int, default 10
1096
1128
Number of histogram bins to be used.
1097
- **kwds
1129
+ %s
1130
+ **kwargs
1098
1131
Additional keyword arguments are documented in
1099
1132
:meth:`DataFrame.plot`.
1100
1133
@@ -1124,10 +1157,13 @@ def hist(self, by=None, bins=10, **kwargs):
1124
1157
>>> df['two'] = df['one'] + np.random.randint(1, 7, 6000)
1125
1158
>>> ax = df.plot.hist(bins=12, alpha=0.5)
1126
1159
"""
1127
- return self (kind = "hist" , by = by , bins = bins , ** kwargs )
1128
-
1129
- def kde (self , bw_method = None , ind = None , ** kwargs ):
1130
- """
1160
+
1161
+ @Appender (_hist_docs % _shared_docs )
1162
+ def hist (self , by = None , bins = 10 , figsize = None , subplots = False , sharex = None ,
1163
+ sharey = False , layout = None , title = None , ** kwargs ):
1164
+ return self (kind = "hist" , by = by , bins = bins , figsize = figsize , subplots = subplots ,
1165
+ sharex = sharex , sharey = sharey , layout = layout , title = title , ** kwargs )
1166
+ kde_docs = """
1131
1167
Generate Kernel Density Estimate plot using Gaussian kernels.
1132
1168
1133
1169
In statistics, `kernel density estimation`_ (KDE) is a non-parametric
@@ -1150,7 +1186,8 @@ def kde(self, bw_method=None, ind=None, **kwargs):
1150
1186
1000 equally spaced points are used. If `ind` is a NumPy array, the
1151
1187
KDE is evaluated at the points passed. If `ind` is an integer,
1152
1188
`ind` number of equally spaced points are used.
1153
- **kwds : optional
1189
+ %s
1190
+ **kwargs : optional
1154
1191
Additional keyword arguments are documented in
1155
1192
:meth:`pandas.%(this-datatype)s.plot`.
1156
1193
@@ -1232,12 +1269,17 @@ def kde(self, bw_method=None, ind=None, **kwargs):
1232
1269
1233
1270
>>> ax = df.plot.kde(ind=[1, 2, 3, 4, 5, 6])
1234
1271
"""
1235
- return self (kind = "kde" , bw_method = bw_method , ind = ind , ** kwargs )
1272
+
1273
+ @Appender (_kde_docs % _shared_docs )
1274
+ def kde (self , bw_method = None , ind = None , figsize = None , subplots = False , sharex = None ,
1275
+ sharey = False , layout = None , title = None , ** kwargs ):
1276
+ return self (kind = "kde" , bw_method = bw_method , ind = ind , figsize = figsize ,
1277
+ subplots = subplots , sharex = sharex , sharey = sharey , layout = layout ,
1278
+ ** kwargs )
1236
1279
1237
1280
density = kde
1238
1281
1239
- def area (self , x = None , y = None , ** kwargs ):
1240
- """
1282
+ _area_docs = """
1241
1283
Draw a stacked area plot.
1242
1284
1243
1285
An area plot displays quantitative data visually.
@@ -1252,7 +1294,8 @@ def area(self, x=None, y=None, **kwargs):
1252
1294
stacked : bool, default True
1253
1295
Area plots are stacked by default. Set to False to create a
1254
1296
unstacked plot.
1255
- **kwds : optional
1297
+ %s
1298
+ **kwargs : optional
1256
1299
Additional keyword arguments are documented in
1257
1300
:meth:`DataFrame.plot`.
1258
1301
@@ -1307,10 +1350,14 @@ def area(self, x=None, y=None, **kwargs):
1307
1350
... })
1308
1351
>>> ax = df.plot.area(x='day')
1309
1352
"""
1310
- return self (kind = "area" , x = x , y = y , ** kwargs )
1311
1353
1312
- def pie (self , ** kwargs ):
1313
- """
1354
+ @Appender (_area_docs % _shared_docs )
1355
+ def area (self , x = None , y = None , figsize = None , subplots = False , sharex = None ,
1356
+ sharey = False , layout = None , title = None , ** kwargs ):
1357
+ return self (kind = "area" , x = x , y = y , figsize = figsize , subplots = subplots ,
1358
+ sharex = sharex , sharey = sharey , layout = layout , title = title , ** kwargs )
1359
+
1360
+ _pie_docs = """
1314
1361
Generate a pie plot.
1315
1362
1316
1363
A pie plot is a proportional representation of the numerical data in a
@@ -1324,7 +1371,8 @@ def pie(self, **kwargs):
1324
1371
y : int or label, optional
1325
1372
Label or position of the column to plot.
1326
1373
If not provided, ``subplots=True`` argument must be passed.
1327
- **kwds
1374
+ %s
1375
+ **kwargs
1328
1376
Keyword arguments to pass on to :meth:`DataFrame.plot`.
1329
1377
1330
1378
Returns
@@ -1356,16 +1404,16 @@ def pie(self, **kwargs):
1356
1404
1357
1405
>>> plot = df.plot.pie(subplots=True, figsize=(6, 3))
1358
1406
"""
1359
- if (
1360
- isinstance ( self . _parent , ABCDataFrame )
1361
- and kwargs . get ( "y" , None ) is None
1362
- and not kwargs . get ( "subplots" , False )
1363
- ) :
1407
+
1408
+ @ Appender ( _pie_docs % _shared_docs )
1409
+ def pie ( self , y = None , figsize = None , subplots = False , sharex = None ,
1410
+ sharey = False , layout = None , title = None , ** kwargs ):
1411
+ if isinstance ( self . _parent , ABCDataFrame ) and y is None and not subplots :
1364
1412
raise ValueError ("pie requires either y column or 'subplots=True'" )
1365
- return self (kind = "pie" , ** kwargs )
1413
+ return self (kind = "pie" , y = y , figsize = figsize , subplots = subplots , sharex = sharex ,
1414
+ sharey = sharey , layout = layout , title = title , ** kwargs )
1366
1415
1367
- def scatter (self , x , y , s = None , c = None , ** kwargs ):
1368
- """
1416
+ _scatter_docs = """
1369
1417
Create a scatter plot with varying marker point size and color.
1370
1418
1371
1419
The coordinates of each point are defined by two dataframe columns and
@@ -1405,8 +1453,9 @@ def scatter(self, x, y, s=None, c=None, **kwargs):
1405
1453
1406
1454
- A column name or position whose values will be used to color the
1407
1455
marker points according to a colormap.
1456
+ %s
1408
1457
1409
- **kwds
1458
+ **kwargs
1410
1459
Keyword arguments to pass on to :meth:`DataFrame.plot`.
1411
1460
1412
1461
Returns
@@ -1443,10 +1492,15 @@ def scatter(self, x, y, s=None, c=None, **kwargs):
1443
1492
... c='species',
1444
1493
... colormap='viridis')
1445
1494
"""
1446
- return self (kind = "scatter" , x = x , y = y , s = s , c = c , ** kwargs )
1447
1495
1448
- def hexbin (self , x , y , C = None , reduce_C_function = None , gridsize = None , ** kwargs ):
1449
- """
1496
+ @Appender (_scatter_docs % _shared_docs )
1497
+ def scatter (self , x , y , s = None , c = None , figsize = None , subplots = False , sharex = None ,
1498
+ sharey = False , layout = None , title = None , ** kwargs ):
1499
+ return self (kind = "scatter" , x = x , y = y , s = s , c = c , figsize = figsize ,
1500
+ subplots = subplots , sharex = sharex , sharey = sharey , layout = layout ,
1501
+ title = title , ** kwargs )
1502
+
1503
+ _hexbin_docs = """
1450
1504
Generate a hexagonal binning plot.
1451
1505
1452
1506
Generate a hexagonal binning plot of `x` versus `y`. If `C` is `None`
@@ -1478,7 +1532,8 @@ def hexbin(self, x, y, C=None, reduce_C_function=None, gridsize=None, **kwargs):
1478
1532
Alternatively, gridsize can be a tuple with two elements
1479
1533
specifying the number of hexagons in the x-direction and the
1480
1534
y-direction.
1481
- **kwds
1535
+ %s
1536
+ **kwargs
1482
1537
Additional keyword arguments are documented in
1483
1538
:meth:`DataFrame.plot`.
1484
1539
@@ -1527,12 +1582,19 @@ def hexbin(self, x, y, C=None, reduce_C_function=None, gridsize=None, **kwargs):
1527
1582
... gridsize=10,
1528
1583
... cmap="viridis")
1529
1584
"""
1585
+
1586
+ @Appender (_hexbin_docs % _shared_docs )
1587
+ def hexbin (self , x , y , C = None , reduce_C_function = None , gridsize = None , figsize = None ,
1588
+ subplots = False , sharex = None , sharey = False , layout = None , title = None ,
1589
+ ** kwargs ):
1530
1590
if reduce_C_function is not None :
1531
1591
kwargs ["reduce_C_function" ] = reduce_C_function
1532
1592
if gridsize is not None :
1533
1593
kwargs ["gridsize" ] = gridsize
1534
1594
1535
- return self (kind = "hexbin" , x = x , y = y , C = C , ** kwargs )
1595
+ return self (kind = "hexbin" , x = x , y = y , C = C , reduce_C_function = reduce_C_function ,
1596
+ gridsize = gridsize , figsize = figsize , subplots = subplots ,
1597
+ sharex = sharex , sharey = sharey , layout = layout , title = title , ** kwargs )
1536
1598
1537
1599
1538
1600
_backends = {}
0 commit comments