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