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