@@ -385,6 +385,45 @@ def hist_frame(
385
385
"""
386
386
387
387
388
+ _bar_or_line_doc = """
389
+ Parameters
390
+ ----------
391
+ x : label or position, optional
392
+ Allows plotting of one column versus another. If not specified,
393
+ the index of the DataFrame is used.
394
+ y : label or position, optional
395
+ Allows plotting of one column versus another. If not specified,
396
+ all numerical columns are used.
397
+ color : str, array_like, or dict, optional
398
+ The color for each of the DataFrame's columns. Possible values are:
399
+
400
+ - A single color string referred to by name, RGB or RGBA code,
401
+ for instance 'red' or '#a98d19'.
402
+
403
+ - A sequence of color strings referred to by name, RGB or RGBA
404
+ code, which will be used for each column recursively. For
405
+ instance ['green','yellow'] each column's %(kind)s will be filled in
406
+ green or yellow, alternatively.
407
+
408
+ - A dict of the form {column name : color}, so that each column will be
409
+ colored accordingly. For example, if your columns are called `a` and
410
+ `b`, then passing {'a': 'green', 'b': 'red'} will color %(kind)ss for
411
+ column `a` in green and %(kind)ss for column `b` in red.
412
+
413
+ .. versionadded:: 1.1.0
414
+
415
+ **kwargs
416
+ Additional keyword arguments are documented in
417
+ :meth:`DataFrame.plot`.
418
+
419
+ Returns
420
+ -------
421
+ matplotlib.axes.Axes or np.ndarray of them
422
+ An ndarray is returned with one :class:`matplotlib.axes.Axes`
423
+ per column when ``subplots=True``.
424
+ """
425
+
426
+
388
427
@Substitution (backend = "" )
389
428
@Appender (_boxplot_doc )
390
429
def boxplot (
@@ -848,31 +887,8 @@ def __call__(self, *args, **kwargs):
848
887
849
888
__call__ .__doc__ = __doc__
850
889
851
- def line ( self , x = None , y = None , ** kwargs ):
890
+ @ Appender (
852
891
"""
853
- Plot Series or DataFrame as lines.
854
-
855
- This function is useful to plot lines using DataFrame's values
856
- as coordinates.
857
-
858
- Parameters
859
- ----------
860
- x : int or str, optional
861
- Columns to use for the horizontal axis.
862
- Either the location or the label of the columns to be used.
863
- By default, it will use the DataFrame indices.
864
- y : int, str, or list of them, optional
865
- The values to be plotted.
866
- Either the location or the label of the columns to be used.
867
- By default, it will use the remaining DataFrame numeric columns.
868
- **kwargs
869
- Keyword arguments to pass on to :meth:`DataFrame.plot`.
870
-
871
- Returns
872
- -------
873
- :class:`matplotlib.axes.Axes` or :class:`numpy.ndarray`
874
- Return an ndarray when ``subplots=True``.
875
-
876
892
See Also
877
893
--------
878
894
matplotlib.pyplot.plot : Plot y versus x as lines and/or markers.
@@ -907,6 +923,16 @@ def line(self, x=None, y=None, **kwargs):
907
923
>>> type(axes)
908
924
<class 'numpy.ndarray'>
909
925
926
+ .. plot::
927
+ :context: close-figs
928
+
929
+ Let's repeat the same example, but specifying colors for
930
+ each column (in this case, for each animal).
931
+
932
+ >>> axes = df.plot.line(
933
+ ... subplots=True, color={"pig": "pink", "horse": "#742802"}
934
+ ... )
935
+
910
936
.. plot::
911
937
:context: close-figs
912
938
@@ -915,36 +941,20 @@ def line(self, x=None, y=None, **kwargs):
915
941
916
942
>>> lines = df.plot.line(x='pig', y='horse')
917
943
"""
918
- return self (kind = "line" , x = x , y = y , ** kwargs )
919
-
920
- def bar (self , x = None , y = None , ** kwargs ):
944
+ )
945
+ @Substitution (kind = "line" )
946
+ @Appender (_bar_or_line_doc )
947
+ def line (self , x = None , y = None , ** kwargs ):
921
948
"""
922
- Vertical bar plot.
923
-
924
- A bar plot is a plot that presents categorical data with
925
- rectangular bars with lengths proportional to the values that they
926
- represent. A bar plot shows comparisons among discrete categories. One
927
- axis of the plot shows the specific categories being compared, and the
928
- other axis represents a measured value.
929
-
930
- Parameters
931
- ----------
932
- x : label or position, optional
933
- Allows plotting of one column versus another. If not specified,
934
- the index of the DataFrame is used.
935
- y : label or position, optional
936
- Allows plotting of one column versus another. If not specified,
937
- all numerical columns are used.
938
- **kwargs
939
- Additional keyword arguments are documented in
940
- :meth:`DataFrame.plot`.
949
+ Plot Series or DataFrame as lines.
941
950
942
- Returns
943
- -------
944
- matplotlib.axes.Axes or np.ndarray of them
945
- An ndarray is returned with one :class:`matplotlib.axes.Axes`
946
- per column when ``subplots=True``.
951
+ This function is useful to plot lines using DataFrame's values
952
+ as coordinates.
953
+ """
954
+ return self (kind = "line" , x = x , y = y , ** kwargs )
947
955
956
+ @Appender (
957
+ """
948
958
See Also
949
959
--------
950
960
DataFrame.plot.barh : Horizontal bar plot.
@@ -986,6 +996,17 @@ def bar(self, x=None, y=None, **kwargs):
986
996
>>> axes = df.plot.bar(rot=0, subplots=True)
987
997
>>> axes[1].legend(loc=2) # doctest: +SKIP
988
998
999
+ If you don't like the default colours, you can specify how you'd
1000
+ like each column to be colored.
1001
+
1002
+ .. plot::
1003
+ :context: close-figs
1004
+
1005
+ >>> axes = df.plot.bar(
1006
+ ... rot=0, subplots=True, color={"speed": "red", "lifespan": "green"}
1007
+ ... )
1008
+ >>> axes[1].legend(loc=2) # doctest: +SKIP
1009
+
989
1010
Plot a single column.
990
1011
991
1012
.. plot::
@@ -999,32 +1020,24 @@ def bar(self, x=None, y=None, **kwargs):
999
1020
:context: close-figs
1000
1021
1001
1022
>>> ax = df.plot.bar(x='lifespan', rot=0)
1023
+ """
1024
+ )
1025
+ @Substitution (kind = "bar" )
1026
+ @Appender (_bar_or_line_doc )
1027
+ def bar (self , x = None , y = None , ** kwargs ):
1002
1028
"""
1003
- return self (kind = "bar" , x = x , y = y , ** kwargs )
1004
-
1005
- def barh (self , x = None , y = None , ** kwargs ):
1006
- """
1007
- Make a horizontal bar plot.
1029
+ Vertical bar plot.
1008
1030
1009
- A horizontal bar plot is a plot that presents quantitative data with
1031
+ A bar plot is a plot that presents categorical data with
1010
1032
rectangular bars with lengths proportional to the values that they
1011
1033
represent. A bar plot shows comparisons among discrete categories. One
1012
1034
axis of the plot shows the specific categories being compared, and the
1013
1035
other axis represents a measured value.
1036
+ """
1037
+ return self (kind = "bar" , x = x , y = y , ** kwargs )
1014
1038
1015
- Parameters
1016
- ----------
1017
- x : label or position, default DataFrame.index
1018
- Column to be used for categories.
1019
- y : label or position, default All numeric columns in dataframe
1020
- Columns to be plotted from the DataFrame.
1021
- **kwargs
1022
- Keyword arguments to pass on to :meth:`DataFrame.plot`.
1023
-
1024
- Returns
1025
- -------
1026
- :class:`matplotlib.axes.Axes` or numpy.ndarray of them
1027
-
1039
+ @Appender (
1040
+ """
1028
1041
See Also
1029
1042
--------
1030
1043
DataFrame.plot.bar: Vertical bar plot.
@@ -1054,6 +1067,13 @@ def barh(self, x=None, y=None, **kwargs):
1054
1067
... 'lifespan': lifespan}, index=index)
1055
1068
>>> ax = df.plot.barh()
1056
1069
1070
+ We can specify colors for each column
1071
+
1072
+ .. plot::
1073
+ :context: close-figs
1074
+
1075
+ >>> ax = df.plot.barh(color={"speed": "red", "lifespan": "green"})
1076
+
1057
1077
Plot a column of the DataFrame to a horizontal bar plot
1058
1078
1059
1079
.. plot::
@@ -1079,6 +1099,19 @@ def barh(self, x=None, y=None, **kwargs):
1079
1099
>>> df = pd.DataFrame({'speed': speed,
1080
1100
... 'lifespan': lifespan}, index=index)
1081
1101
>>> ax = df.plot.barh(x='lifespan')
1102
+ """
1103
+ )
1104
+ @Substitution (kind = "bar" )
1105
+ @Appender (_bar_or_line_doc )
1106
+ def barh (self , x = None , y = None , ** kwargs ):
1107
+ """
1108
+ Make a horizontal bar plot.
1109
+
1110
+ A horizontal bar plot is a plot that presents quantitative data with
1111
+ rectangular bars with lengths proportional to the values that they
1112
+ represent. A bar plot shows comparisons among discrete categories. One
1113
+ axis of the plot shows the specific categories being compared, and the
1114
+ other axis represents a measured value.
1082
1115
"""
1083
1116
return self (kind = "barh" , x = x , y = y , ** kwargs )
1084
1117
0 commit comments