pandas 中的分组散点图

Grouped scatter plot in pandas

假设我在数据框中有这个 table:

     DATE          SUNHOUR    YEAR
---  ----------  ---------  ------
281  2018-10-09       11.1    2018
 29  2018-01-30        6.5    2018
266  2018-09-24        6.2    2018
115  2018-04-26       13.4    2018
 69  2018-03-11        7.3    2018
158  2019-06-08       13.7    2019
287  2019-10-15        8.5    2019
177  2019-06-27       15.9    2019
136  2019-05-17       11.5    2019
 59  2019-03-01       10.1    2019

这会给我一个散点图:

df.plot.scatter(x='DATE', y='SUNHOUR')

现在,当我查看 at the documentation 时,我读到参数 c 可以采用 列名称或位置,其值将用于根据以下条件为标记点着色颜色图。 所以我认为每年都有不同的颜色:

df.plot.scatter(x='DATE', y='SUNHOUR', c='YEAR')

但是这个returns:

ValueError: 'c' argument must be a color, a sequence of colors, or a sequence of numbers, not ['2018' '2018' '2018' '2018' '2018' '2019' '2019' '2019' '2019' '2019']

我错过了什么?

根据文档:

c : str, int or array_like, optional
    The color of each point. Possible values are:
    * A single color string referred to by name, RGB or RGBA code, for instance ‘red’ or ‘#a98d19’.
    * A sequence of color strings referred to by name, RGB or RGBA code, which will be used for each point’s color recursively. For instance [‘green’,’yellow’] all points will be filled in green or yellow, alternatively.
    * A column name or position whose values will be used to color the marker points according to a colormap.

您不能只给出任何值,而是一个包含颜色值的列(例如,您将有一个包含值 "green"、"red" 等的列

你想做什么,看看here