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