Matplotlib:用第三维(类别)改变线条颜色的二维图
如何根据第三维度/类别更改常规二维图的颜色? 例如,假设我们记录了车辆冷却液温度随时间的变化。我们将时间绘制在水平轴上,将温度绘制在垂直轴上。我们还记录了每次“高温指示灯”是否打开或关闭。当灯亮时,我们希望绘制的灯为红色;如果指示灯关闭,则为绿色。
它基本上是一个三维数据图,我们将特定颜色的线条分配给第三个数据维度 (z)。对于这个特定的应用程序,我不想查看具有 3 个轴的 3-D 图;只是一个常规的二维图,适当地改变线条颜色。
How do I change the color of a regular 2-D plot according to a third dimension/category?
For example, suppose we recorded the coolant temperature of a vehicle with time. We plot that with time on the horizontal axis, and temp on the vertical axis. We also recorded at each time whether the "high temp indicator light" was on or off. When the light was on, we want the plotted light to be red; green if the indicator was off.
It's basically a plot of 3-D data where we assign a particular color of line to the third data dimension (z). I do not want to look at a 3-D plot with 3 axes for this particular application; just a regular 2-D plot changing the line color as appropriate.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以使用
SciPy.Cookbook.MulticoloredLine
。另一种方法可能是 - 在绘图底部添加开/关 ColorBar 。
You can use
SciPy.Cookbook.MulticoloredLine
.Another approach could be - add on/off ColorBar in the bottom of plot.