1
1
import importlib
2
2
import warnings
3
3
4
+ import numpy as np
5
+
4
6
from pandas ._config import get_option
5
7
6
8
from pandas .util ._decorators import Appender , Substitution
10
12
11
13
from pandas .core .base import PandasObject
12
14
15
+ _shared_docs = """figsize : a tuple (width, height) in inches
16
+ subplots : boolean, default False
17
+ Make separate subplots for each column
18
+ sharex : boolean, default True if ax is None else False
19
+ In case subplots=True, share x axis and set some x axis labels to invisible;
20
+ defaults to True if ax is None otherwise False if an ax is passed in;
21
+ Be aware, that passing in both an ax and sharex=True will alter all x axis
22
+ labels for all axis in a figure!
23
+ sharey : boolean, default False
24
+ In case subplots=True, share y axis and set some y axis labels to subplots
25
+ layout : tuple (optional)
26
+ (rows, columns) for the layout of subplots
27
+ title : string or list
28
+ Title to use for the plot. If a string is passed, print the string at the
29
+ top of the figure. If a list is passed and subplots is True, print each item
30
+ in the list above the corresponding subplot."""
13
31
14
32
def hist_series (
15
33
self ,
@@ -852,8 +870,7 @@ def __call__(self, *args, **kwargs):
852
870
853
871
return plot_backend .plot (data , kind = kind , ** kwargs )
854
872
855
- def line (self , x = None , y = None , ** kwargs ):
856
- """
873
+ _line_docs = """
857
874
Plot Series or DataFrame as lines.
858
875
859
876
This function is useful to plot lines using DataFrame's values
@@ -869,6 +886,7 @@ def line(self, x=None, y=None, **kwargs):
869
886
The values to be plotted.
870
887
Either the location or the label of the columns to be used.
871
888
By default, it will use the remaining DataFrame numeric columns.
889
+ %s
872
890
**kwargs
873
891
Keyword arguments to pass on to :meth:`DataFrame.plot`.
874
892
@@ -919,10 +937,14 @@ def line(self, x=None, y=None, **kwargs):
919
937
920
938
>>> lines = df.plot.line(x='pig', y='horse')
921
939
"""
922
- return self (kind = "line" , x = x , y = y , ** kwargs )
923
940
924
- def bar (self , x = None , y = None , ** kwargs ):
925
- """
941
+ @Appender (_line_docs % _shared_docs )
942
+ def line (self , x = None , y = None , figsize = None , subplots = False , sharex = None ,
943
+ sharey = False , layout = None , title = None , ** kwargs ):
944
+ return self (kind = "line" , x = x , y = y , figsize = figsize , subplots = subplots ,
945
+ sharex = sharex , sharey = sharey , layout = layout , title = title , ** kwargs )
946
+
947
+ _bar_docs = """
926
948
Vertical bar plot.
927
949
928
950
A bar plot is a plot that presents categorical data with
@@ -939,6 +961,7 @@ def bar(self, x=None, y=None, **kwargs):
939
961
y : label or position, optional
940
962
Allows plotting of one column versus another. If not specified,
941
963
all numerical columns are used.
964
+ %s
942
965
**kwargs
943
966
Additional keyword arguments are documented in
944
967
:meth:`DataFrame.plot`.
@@ -1004,10 +1027,14 @@ def bar(self, x=None, y=None, **kwargs):
1004
1027
1005
1028
>>> ax = df.plot.bar(x='lifespan', rot=0)
1006
1029
"""
1007
- return self (kind = "bar" , x = x , y = y , ** kwargs )
1008
1030
1009
- def barh (self , x = None , y = None , ** kwargs ):
1010
- """
1031
+ @Appender (_bar_docs % _shared_docs )
1032
+ def bar (self , x = None , y = None , figsize = None , subplots = False , sharex = None ,
1033
+ sharey = False , layout = None , title = None , ** kwargs ):
1034
+ return self (kind = "bar" , x = x , y = y , figsize = figsize , subplots = subplots ,
1035
+ sharex = sharex , sharey = sharey , layout = layout , title = title , ** kwargs )
1036
+
1037
+ _barh_docs = """
1011
1038
Make a horizontal bar plot.
1012
1039
1013
1040
A horizontal bar plot is a plot that presents quantitative data with
@@ -1022,6 +1049,7 @@ def barh(self, x=None, y=None, **kwargs):
1022
1049
Column to be used for categories.
1023
1050
y : label or position, default All numeric columns in dataframe
1024
1051
Columns to be plotted from the DataFrame.
1052
+ %s
1025
1053
**kwargs
1026
1054
Keyword arguments to pass on to :meth:`DataFrame.plot`.
1027
1055
@@ -1083,11 +1111,15 @@ def barh(self, x=None, y=None, **kwargs):
1083
1111
>>> df = pd.DataFrame({'speed': speed,
1084
1112
... 'lifespan': lifespan}, index=index)
1085
1113
>>> ax = df.plot.barh(x='lifespan')
1086
- """
1087
- return self (kind = "barh" , x = x , y = y , ** kwargs )
1114
+ """
1115
+
1116
+ @Appender (_barh_docs % _shared_docs )
1117
+ def barh (self , x = None , y = None , figsize = None , subplots = False , sharex = None ,
1118
+ sharey = False , layout = None , title = None , ** kwargs ):
1119
+ return self (kind = "barh" , x = x , y = y , figsize = figsize , subplots = subplots ,
1120
+ sharex = sharex , sharey = sharey , layout = layout , title = title , ** kwargs )
1088
1121
1089
- def box (self , by = None , ** kwargs ):
1090
- r"""
1122
+ _box_docs = r"""
1091
1123
Make a box plot of the DataFrame columns.
1092
1124
1093
1125
A box plot is a method for graphically depicting groups of numerical
@@ -1108,7 +1140,8 @@ def box(self, by=None, **kwargs):
1108
1140
----------
1109
1141
by : str or sequence
1110
1142
Column in the DataFrame to group by.
1111
- **kwargs
1143
+ %s
1144
+ **kwargs : optional
1112
1145
Additional keywords are documented in
1113
1146
:meth:`DataFrame.plot`.
1114
1147
@@ -1134,10 +1167,14 @@ def box(self, by=None, **kwargs):
1134
1167
>>> df = pd.DataFrame(data, columns=list('ABCD'))
1135
1168
>>> ax = df.plot.box()
1136
1169
"""
1137
- return self (kind = "box" , by = by , ** kwargs )
1138
1170
1139
- def hist (self , by = None , bins = 10 , ** kwargs ):
1140
- """
1171
+ @Appender (_box_docs % _shared_docs )
1172
+ def box (self , by = None , figsize = None , subplots = False , sharex = None , sharey = False ,
1173
+ layout = None , title = None , ** kwargs ):
1174
+ return self (kind = "box" , by = by , figsize = figsize , subplots = subplots ,
1175
+ sharex = sharex , sharey = sharey , layout = layout , title = title , ** kwargs )
1176
+
1177
+ _hist_docs = """
1141
1178
Draw one histogram of the DataFrame's columns.
1142
1179
1143
1180
A histogram is a representation of the distribution of data.
@@ -1151,6 +1188,7 @@ def hist(self, by=None, bins=10, **kwargs):
1151
1188
Column in the DataFrame to group by.
1152
1189
bins : int, default 10
1153
1190
Number of histogram bins to be used.
1191
+ %s
1154
1192
**kwargs
1155
1193
Additional keyword arguments are documented in
1156
1194
:meth:`DataFrame.plot`.
@@ -1181,10 +1219,13 @@ def hist(self, by=None, bins=10, **kwargs):
1181
1219
>>> df['two'] = df['one'] + np.random.randint(1, 7, 6000)
1182
1220
>>> ax = df.plot.hist(bins=12, alpha=0.5)
1183
1221
"""
1184
- return self (kind = "hist" , by = by , bins = bins , ** kwargs )
1185
1222
1186
- def kde (self , bw_method = None , ind = None , ** kwargs ):
1187
- """
1223
+ @Appender (_hist_docs % _shared_docs )
1224
+ def hist (self , by = None , bins = 10 , figsize = None , subplots = False , sharex = None ,
1225
+ sharey = False , layout = None , title = None , ** kwargs ):
1226
+ return self (kind = "hist" , by = by , bins = bins , figsize = figsize , subplots = subplots ,
1227
+ sharex = sharex , sharey = sharey , layout = layout , title = title , ** kwargs )
1228
+ _kde_docs = """
1188
1229
Generate Kernel Density Estimate plot using Gaussian kernels.
1189
1230
1190
1231
In statistics, `kernel density estimation`_ (KDE) is a non-parametric
@@ -1207,9 +1248,10 @@ def kde(self, bw_method=None, ind=None, **kwargs):
1207
1248
1000 equally spaced points are used. If `ind` is a NumPy array, the
1208
1249
KDE is evaluated at the points passed. If `ind` is an integer,
1209
1250
`ind` number of equally spaced points are used.
1210
- **kwargs
1251
+ %s
1252
+ **kwargs : optional
1211
1253
Additional keyword arguments are documented in
1212
- :meth:`pandas.%(this-datatype)s.plot`.
1254
+ :meth:`pandas.%% (this-datatype)s.plot`.
1213
1255
1214
1256
Returns
1215
1257
-------
@@ -1289,12 +1331,17 @@ def kde(self, bw_method=None, ind=None, **kwargs):
1289
1331
1290
1332
>>> ax = df.plot.kde(ind=[1, 2, 3, 4, 5, 6])
1291
1333
"""
1292
- return self (kind = "kde" , bw_method = bw_method , ind = ind , ** kwargs )
1334
+
1335
+ @Appender (_kde_docs % _shared_docs )
1336
+ def kde (self , bw_method = None , ind = None , figsize = None , subplots = False , sharex = None ,
1337
+ sharey = False , layout = None , title = None , ** kwargs ):
1338
+ return self (kind = "kde" , bw_method = bw_method , ind = ind , figsize = figsize ,
1339
+ subplots = subplots , sharex = sharex , sharey = sharey , layout = layout ,
1340
+ ** kwargs )
1293
1341
1294
1342
density = kde
1295
1343
1296
- def area (self , x = None , y = None , ** kwargs ):
1297
- """
1344
+ _area_docs = """
1298
1345
Draw a stacked area plot.
1299
1346
1300
1347
An area plot displays quantitative data visually.
@@ -1309,7 +1356,8 @@ def area(self, x=None, y=None, **kwargs):
1309
1356
stacked : bool, default True
1310
1357
Area plots are stacked by default. Set to False to create a
1311
1358
unstacked plot.
1312
- **kwargs
1359
+ %s
1360
+ **kwargs : optional
1313
1361
Additional keyword arguments are documented in
1314
1362
:meth:`DataFrame.plot`.
1315
1363
@@ -1364,10 +1412,14 @@ def area(self, x=None, y=None, **kwargs):
1364
1412
... })
1365
1413
>>> ax = df.plot.area(x='day')
1366
1414
"""
1367
- return self (kind = "area" , x = x , y = y , ** kwargs )
1368
1415
1369
- def pie (self , ** kwargs ):
1370
- """
1416
+ @Appender (_area_docs % _shared_docs )
1417
+ def area (self , x = None , y = None , figsize = None , subplots = False , sharex = None ,
1418
+ sharey = False , layout = None , title = None , ** kwargs ):
1419
+ return self (kind = "area" , x = x , y = y , figsize = figsize , subplots = subplots ,
1420
+ sharex = sharex , sharey = sharey , layout = layout , title = title , ** kwargs )
1421
+
1422
+ _pie_docs = """
1371
1423
Generate a pie plot.
1372
1424
1373
1425
A pie plot is a proportional representation of the numerical data in a
@@ -1381,6 +1433,7 @@ def pie(self, **kwargs):
1381
1433
y : int or label, optional
1382
1434
Label or position of the column to plot.
1383
1435
If not provided, ``subplots=True`` argument must be passed.
1436
+ %s
1384
1437
**kwargs
1385
1438
Keyword arguments to pass on to :meth:`DataFrame.plot`.
1386
1439
@@ -1413,16 +1466,16 @@ def pie(self, **kwargs):
1413
1466
1414
1467
>>> plot = df.plot.pie(subplots=True, figsize=(6, 3))
1415
1468
"""
1416
- if (
1417
- isinstance ( self . _parent , ABCDataFrame )
1418
- and kwargs . get ( "y" , None ) is None
1419
- and not kwargs . get ( "subplots" , False )
1420
- ) :
1469
+
1470
+ @ Appender ( _pie_docs % _shared_docs )
1471
+ def pie ( self , y = None , figsize = None , subplots = False , sharex = None ,
1472
+ sharey = False , layout = None , title = None , ** kwargs ):
1473
+ if isinstance ( self . _parent , ABCDataFrame ) and y is None and not subplots :
1421
1474
raise ValueError ("pie requires either y column or 'subplots=True'" )
1422
- return self (kind = "pie" , ** kwargs )
1475
+ return self (kind = "pie" , y = y , figsize = figsize , subplots = subplots , sharex = sharex ,
1476
+ sharey = sharey , layout = layout , title = title , ** kwargs )
1423
1477
1424
- def scatter (self , x , y , s = None , c = None , ** kwargs ):
1425
- """
1478
+ _scatter_docs = """
1426
1479
Create a scatter plot with varying marker point size and color.
1427
1480
1428
1481
The coordinates of each point are defined by two dataframe columns and
@@ -1462,7 +1515,7 @@ def scatter(self, x, y, s=None, c=None, **kwargs):
1462
1515
1463
1516
- A column name or position whose values will be used to color the
1464
1517
marker points according to a colormap.
1465
-
1518
+ %s
1466
1519
**kwargs
1467
1520
Keyword arguments to pass on to :meth:`DataFrame.plot`.
1468
1521
@@ -1500,10 +1553,15 @@ def scatter(self, x, y, s=None, c=None, **kwargs):
1500
1553
... c='species',
1501
1554
... colormap='viridis')
1502
1555
"""
1503
- return self (kind = "scatter" , x = x , y = y , s = s , c = c , ** kwargs )
1504
1556
1505
- def hexbin (self , x , y , C = None , reduce_C_function = None , gridsize = None , ** kwargs ):
1506
- """
1557
+ @Appender (_scatter_docs % _shared_docs )
1558
+ def scatter (self , x , y , s = None , c = None , figsize = None , subplots = False , sharex = None ,
1559
+ sharey = False , layout = None , title = None , ** kwargs ):
1560
+ return self (kind = "scatter" , x = x , y = y , s = s , c = c , figsize = figsize ,
1561
+ subplots = subplots , sharex = sharex , sharey = sharey , layout = layout ,
1562
+ title = title , ** kwargs )
1563
+
1564
+ _hexbin_docs = """
1507
1565
Generate a hexagonal binning plot.
1508
1566
1509
1567
Generate a hexagonal binning plot of `x` versus `y`. If `C` is `None`
@@ -1535,6 +1593,7 @@ def hexbin(self, x, y, C=None, reduce_C_function=None, gridsize=None, **kwargs):
1535
1593
Alternatively, gridsize can be a tuple with two elements
1536
1594
specifying the number of hexagons in the x-direction and the
1537
1595
y-direction.
1596
+ %s
1538
1597
**kwargs
1539
1598
Additional keyword arguments are documented in
1540
1599
:meth:`DataFrame.plot`.
@@ -1584,12 +1643,14 @@ def hexbin(self, x, y, C=None, reduce_C_function=None, gridsize=None, **kwargs):
1584
1643
... gridsize=10,
1585
1644
... cmap="viridis")
1586
1645
"""
1587
- if reduce_C_function is not None :
1588
- kwargs ["reduce_C_function" ] = reduce_C_function
1589
- if gridsize is not None :
1590
- kwargs ["gridsize" ] = gridsize
1591
1646
1592
- return self (kind = "hexbin" , x = x , y = y , C = C , ** kwargs )
1647
+ @Appender (_hexbin_docs % _shared_docs )
1648
+ def hexbin (self , x , y , C = None , reduce_C_function = np .mean , gridsize = 100 ,
1649
+ figsize = None , subplots = False , sharex = None , sharey = False , layout = None ,
1650
+ title = None , ** kwargs ):
1651
+ return self (kind = "hexbin" , x = x , y = y , C = C , reduce_C_function = reduce_C_function ,
1652
+ gridsize = gridsize , figsize = figsize , subplots = subplots ,
1653
+ sharex = sharex , sharey = sharey , layout = layout , title = title , ** kwargs )
1593
1654
1594
1655
1595
1656
_backends = {}
0 commit comments