我有一个数据框
Company Id ON/OFF Level of Fuel
DateTime
2018-08-18 00:00:10 25750275 1 82.048
2018-08-18 00:00:39 25750275 1 82.048
2018-08-18 00:01:09 25750275 1 79.936
2018-08-18 00:01:39 25750275 1 79.600
2018-08-18 00:02:10 25750275 1 78.480
我想要的是在 x 轴上带有 DateTime 索引的线图,在 y 轴上带有“公司 ID”,并且该线应该根据“ON?OFF”列中的值(即 [0,1])具有不同的颜色或样式。
从 seaborn文档中,我尝试调用以下函数
sns.catplot(x=data.index, y="Level of Fuel", hue="ON/OFF",
palette={"ON": 1, "OFF": 0},
markers=["^", "o"], linestyles=["-", "--"],
kind="point",data=data)
但我得到一个KeyError:0
跟踪如下
KeyError Traceback (most recent call last)
<ipython-input-91-cf07ea2f9cbf> in <module>
2 palette={"ON": 1, "OFF": 0},
3 markers=["^", "o"], linestyles=["-", "--"],
----> 4 kind="point",data=data)
~/.local/lib/python3.6/site-packages/seaborn/categorical.py in catplot(x, y, hue, data, row, col, col_wrap, estimator, ci, n_boot, units, seed, order, hue_order, row_order, col_order, kind, height, aspect, orient, color, palette, legend, legend_out, sharex, sharey, margin_titles, facet_kws, **kwargs)
3729 # so we need to define ``palette`` to get default behavior for the
3730 # categorical functions
-> 3731 p.establish_colors(color, palette, 1)
3732 if kind != "point" or hue is not None:
3733 palette = p.colors
~/.local/lib/python3.6/site-packages/seaborn/categorical.py in establish_colors(self, color, palette, saturation)
301 else:
302 levels = self.hue_names
--> 303 palette = [palette[l] for l in levels]
304
305 colors = color_palette(palette, n_colors)
~/.local/lib/python3.6/site-packages/seaborn/categorical.py in <listcomp>(.0)
301 else:
302 levels = self.hue_names
--> 303 palette = [palette[l] for l in levels]
304
305 colors = color_palette(palette, n_colors)
KeyError: 0