【发布时间】:2021-12-07 00:31:03
【问题描述】:
我得到了一份close 数据列表,它既是消极的又是积极的。当我绘制一条线时,我想将正值显示为绿色段,将负值显示为红色段。我有以下 df 格式的数据:
A price B side size signal \
time
2019-06-12 03:54:26.668990 4603.35936 7990.0 4583.96620 Buy 20 True
2019-06-12 03:54:26.668990 4603.24884 7990.0 4583.96620 Buy 38 True
2019-06-12 03:54:26.668990 4603.26808 7990.0 4583.96620 Buy 69 True
2019-06-12 03:54:26.668990 4603.32670 7990.0 4583.96620 Buy 25 True
2019-06-12 03:54:26.668990 4603.32670 7990.0 4583.96620 Buy 450 True
... ... ... ... ... ... ...
2019-06-12 12:07:48.793863 3997.85136 8043.5 4375.44562 Buy 22 False
2019-06-12 12:07:48.793863 3997.87648 8044.0 4375.44562 Buy 1300 False
2019-06-12 12:07:48.793863 3997.87616 8044.0 4375.44562 Buy 6 False
2019-06-12 12:07:48.793863 3997.89530 8044.0 4375.44562 Buy 1000 False
2019-06-12 12:07:48.793863 3997.90046 8044.0 4375.44562 Buy 280 False
如果信号为真,则显示绿色,否则显示红色。我找到了this 示例,但我很难理解它。
到目前为止我尝试过的代码如下
first=combine[:200000] #DF
x = first.index
y = first.price.values
points = np.array([x, y]).T.reshape(-1, 1, 2)
segments = np.concatenate([points[:-1], points[1:]], axis=1)
from matplotlib.colors import LinearSegmentedColormap
cmap=LinearSegmentedColormap.from_list('rg',["r", "g"], N=256)
print(cmap)
我无法弄清楚如何使用Signal 值来为段着色
【问题讨论】:
标签: python matplotlib colormap