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