熊猫中的散点图

时间:2020-05-04 11:50:24

标签: python pandas scatter-plot

说我在数据框中有这张桌子:

server

这会给我一个散点图:

     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

scatter

现在,当我看at the documentation时,我读到参数df.plot.scatter(x='DATE', y='SUNHOUR') 可以列名或位置,其值将用于根据颜色图为标记点着色。 / em>因此,我认为每年可以使用不同的颜色:

c

但这返回:

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

我想念什么?

1 个答案:

答案 0 :(得分:1)

根据文档:

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.

您不能只给出任何值,而只能给出颜色值的列(例如,您将给出一列值,包括“绿色”,“红色”等。

对于您要尝试做的事情,请看一下here