@@ -865,6 +865,21 @@ def line(self, x=None, y=None, **kwargs):
865
865
The values to be plotted.
866
866
Either the location or the label of the columns to be used.
867
867
By default, it will use the remaining DataFrame numeric columns.
868
+ color : str, int, array_like, or dict, optional
869
+ The color of each line for each row. Possible values are:
870
+
871
+ - A single color string referred to by name, RGB or RGBA code,
872
+ for instance 'red' or '#a98d19'.
873
+
874
+ - A sequence of color strings referred to by name, RGB or RGBA
875
+ code, which will be used for each line for each row recursively. For
876
+ instance ['green','yellow'] all lines for each row will be filled in green
877
+ or yellow, alternatively.
878
+
879
+ - A dict of the form {column name : color}, so that each row's lines will be
880
+ colored accordingly. For example, if your columns are called `a` and `b`,
881
+ then passing {'a': 'green', 'b': 'red'} will color the lines for column
882
+ `a` in green and lines for column `b` in red.
868
883
**kwargs
869
884
Keyword arguments to pass on to :meth:`DataFrame.plot`.
870
885
@@ -907,6 +922,16 @@ def line(self, x=None, y=None, **kwargs):
907
922
>>> type(axes)
908
923
<class 'numpy.ndarray'>
909
924
925
+ .. plot::
926
+ :context: close-figs
927
+
928
+ Let's repeat the same example, but specifying colors for
929
+ each column (in this case, for each animal).
930
+
931
+ >>> axes = df.plot.line(
932
+ ... subplots=True, color={"pig": "pink", "horse": "#742802"}
933
+ ... )
934
+
910
935
.. plot::
911
936
:context: close-figs
912
937
@@ -935,6 +960,21 @@ def bar(self, x=None, y=None, **kwargs):
935
960
y : label or position, optional
936
961
Allows plotting of one column versus another. If not specified,
937
962
all numerical columns are used.
963
+ color : str, int, array_like, or dict, optional
964
+ The color of each bar for each row. Possible values are:
965
+
966
+ - A single color string referred to by name, RGB or RGBA code,
967
+ for instance 'red' or '#a98d19'.
968
+
969
+ - A sequence of color strings referred to by name, RGB or RGBA
970
+ code, which will be used for each bar for each row recursively. For
971
+ instance ['green','yellow'] all bars for each row will be filled in green
972
+ or yellow, alternatively.
973
+
974
+ - A dict of the form {column name : color}, so that each row's bars will be
975
+ colored accordingly. For example, if your columns are called `a` and `b`,
976
+ then passing {'a': 'green', 'b': 'red'} will color bars for column `a` in
977
+ green and bars for column `b` in red.
938
978
**kwargs
939
979
Additional keyword arguments are documented in
940
980
:meth:`DataFrame.plot`.
@@ -986,6 +1026,17 @@ def bar(self, x=None, y=None, **kwargs):
986
1026
>>> axes = df.plot.bar(rot=0, subplots=True)
987
1027
>>> axes[1].legend(loc=2) # doctest: +SKIP
988
1028
1029
+ If we don't like the default colours, we can specify how we'd
1030
+ like each column to be colored.
1031
+
1032
+ .. plot::
1033
+ :context: close-figs
1034
+
1035
+ >>> axes = df.plot.bar(
1036
+ ... rot=0, subplots=True, color={"speed": "red", "lifespan": "green"}
1037
+ ... )
1038
+ >>> axes[1].legend(loc=2) # doctest: +SKIP
1039
+
989
1040
Plot a single column.
990
1041
991
1042
.. plot::
@@ -1018,6 +1069,21 @@ def barh(self, x=None, y=None, **kwargs):
1018
1069
Column to be used for categories.
1019
1070
y : label or position, default All numeric columns in dataframe
1020
1071
Columns to be plotted from the DataFrame.
1072
+ color : str, int, array_like, or dict, optional
1073
+ The color of each bar for each row. Possible values are:
1074
+
1075
+ - A single color string referred to by name, RGB or RGBA code,
1076
+ for instance 'red' or '#a98d19'.
1077
+
1078
+ - A sequence of color strings referred to by name, RGB or RGBA
1079
+ code, which will be used for each bar for each row recursively. For
1080
+ instance ['green','yellow'] all bars for each row will be filled in green
1081
+ or yellow, alternatively.
1082
+
1083
+ - A dict of the form {column name : color}, so that each row's bars will be
1084
+ colored accordingly. For example, if your columns are called `a` and `b`,
1085
+ then passing {'a': 'green', 'b': 'red'} will color bars for column `a` in
1086
+ green and bars for column `b` in red.
1021
1087
**kwargs
1022
1088
Keyword arguments to pass on to :meth:`DataFrame.plot`.
1023
1089
@@ -1054,6 +1120,13 @@ def barh(self, x=None, y=None, **kwargs):
1054
1120
... 'lifespan': lifespan}, index=index)
1055
1121
>>> ax = df.plot.barh()
1056
1122
1123
+ We can specify colors for each column
1124
+
1125
+ .. plot::
1126
+ :context: close-figs
1127
+
1128
+ >>> ax = df.plot.barh(color={"speed": "red", "lifespan": "green"})
1129
+
1057
1130
Plot a column of the DataFrame to a horizontal bar plot
1058
1131
1059
1132
.. plot::
0 commit comments