袖扣 - OHLC图表上的放错了注释
注释Y位置与我在API调用中设置的位置不符。我在这里做错了吗?
X位置是正确的。
qf=cf.QuantFig(
df,
title=f'{symbol} - {date}',
name=symbol,
theme='pearl',
up_color='green',
down_color='red',
)
qf.add_annotations(
[
{
'x': idx_high,
'y': df.loc[idx_high]['high'],
'text': f'High: {df.loc[idx_high]["high"]}',
'showarrow':False,
'textangle': 0
},
{
'x': idx_low,
'y': df.loc[idx_low]['low'],
'text': f'Low: {df.loc[idx_low]["low"]}',
'showarrow':False,
'textangle': 0
},
]
)
f = qf.figure()
f.show()
The annotation y-position doesn't correspond to the position I set in the API call. Am I doing something wrong here?
The x-position is correct.
qf=cf.QuantFig(
df,
title=f'{symbol} - {date}',
name=symbol,
theme='pearl',
up_color='green',
down_color='red',
)
qf.add_annotations(
[
{
'x': idx_high,
'y': df.loc[idx_high]['high'],
'text': f'High: {df.loc[idx_high]["high"]}',
'showarrow':False,
'textangle': 0
},
{
'x': idx_low,
'y': df.loc[idx_low]['low'],
'text': f'Low: {df.loc[idx_low]["low"]}',
'showarrow':False,
'textangle': 0
},
]
)
f = qf.figure()
f.show()
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为
add_annotations的方式
来自cufflinks
的工作方式与add_annotation
在Plotly中的函数不同。如果您查看袖扣源用于add_annotations。代码的第一部分是使用一些示例库存数据重现烛台图:
然后,如果我使用袖扣中的add_annotations方法,我可以重现与您相同的问题:注释的y值不正确。
但是,如果我使用
add_annotations
f
的方法(这是一个绘图图对象),则注释在正确的位置显示:I think the way
add_annotations
function fromcufflinks
works differently than theadd_annotation
function in plotly. You could probably figure out the exact reason if you look into the cufflinks source for add_annotations.The first part of the code is reproducing a candlestick plot using some sample stocks data:
Then if I use the add_annotations method from cufflinks, I can reproduce the same issue as you: the y values of the annotations aren't correct.
But if I instead use the
add_annotations
method forf
(which is a plotly graph object), then the annotations appear in the correct location: