如何根据价值为绘制曲线的不同段着色
我正在尝试弄清楚如何根据该线的值绘制数据框列在其中变化,但我一直坚持如何获取这些值。
例如,我有此数据框架:
Timestamp Value
-------------------------
0 5:00 4
1 5:01 5
2 5:02 8
3 5:03 12
4 5:04 13
5 5:05 2
...
我简单地运行某种形式的形式:
df.plot(x="Timestamp", y=["Value"], figsize=(9, 8))
以随着时间的推移而变化。
现在,我的值分为不同的类别/垃圾箱,其中:0-5 =“ low”,6-15 =“中”和16+ =“高”。我想拥有相同的图,但是现在曲线上的所有值都对应于“低”为蓝色,对应于“中间”为绿色,并且对应于“高”为红色。因此,我会看到绘制了一条曲线,由“值”列组成,但根据价值分割为不同的颜色。我该如何在Python中实现这一目标?我对如何设置一个索引/键感到困惑,以将值转换为颜色以及.plot()中需要哪些参数才能根据值实际具有颜色。
I am trying to figure out how to plot a dataframe column where the color of the line changes based on its value, but I am stuck on how to get these values referenced.
For example, I have this dataframe:
Timestamp Value
-------------------------
0 5:00 4
1 5:01 5
2 5:02 8
3 5:03 12
4 5:04 13
5 5:05 2
...
I simple run some form of:
df.plot(x="Timestamp", y=["Value"], figsize=(9, 8))
to get a plot of the values changing over time.
Now, I have my values separated into different categories/bins, where: 0-5 = "Low", 6-15 = "Mid" and 16+ = "High". I want to have my same plot, but now with all values on the curve corresponding to "Low" to be blue, corresponding to "Mid" to be green, and corresponding to "High" to be red. So I will see see a single curve plotted, made up from the "Value" column, but segmented into different colors based on value. How can I accomplish this in python? I am confused about how to set up an index/key for translating values to colors and what argument is needed in .plot() to actually have color based on value.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
给定的:
然后:
输出:
Given this:
Then:
Output: