【发布时间】:2019-03-06 15:12:01
【问题描述】:
我正在尝试在另一条线上绘制 ZigZag 线。我的基准线(价格)有最高点和最低点。我正在尝试用一条线连接顶部和底部点。这是一个例子:
这是我的数据集:
这就是我能走多远:
感谢任何帮助。
编辑 1:
这是我不工作的代码:
trend_index = target_out.columns.get_loc("trend_shifted")
close_index = target_out.columns.get_loc("price_close")
for i in range(1, len(target_out)):
if target_out.iloc[i, trend_index] == target_out.iloc[i-1, trend_index] and target_out.iloc[i-1, trend_index] is not None:
target_out.iloc[i, trend_index] = np.nan
target_out.iloc[i-1, trend_index] = target_out.iloc[i-1, close_index]
# multiple line plot
plt.plot( 'ind', 'price_close', data=target_out, marker='o', markerfacecolor='blue', markersize=12, color='skyblue', linewidth=4)
plt.plot( 'ind', 'trend_shifted', data=target_out, marker='', color='olive', linewidth=2)
plt.legend()
trend_shifted 列有ones 和zeros。连续 1 和 0 的第一个元素实际上是之字形的顶部和底部点。其余的点并不重要。确定了最高点和最低点后,我需要画一条线,但由于价格和趋势的值相对不同,图表是不平衡的(我的意思是,价格像 0.00001 但趋势是 0 和 1)
编辑 2:
@rgk 的代码有效。这是输出:
【问题讨论】:
-
你能分享一个代码示例吗?
-
@rgk 当然,你需要什么部分?我的尝试?
-
最主要的是,当您应该绘制两次价格时,您似乎正试图在同一轴上绘制两个系列 - 请参阅下面的答案
-
有点跑题了,但请您分享一下您是如何制作趋势转移专栏的?
-
如何获得之字形值?我正在做类似的事情,如果您有任何想法,请告诉我! stackoverflow.com/questions/63164124/…
标签: python matplotlib zigzag