在库存图中绘制特定行的问题
我正在使用大熊猫在数据框架中使用DateTime索引绘制库存数据图。我想在df_raw [col_name]!= 0的行中绘制黑色标记/a>。当没有数据帧行满足条件时,图显示fine 。
您能帮我理解我在做错什么吗?请注意,该股票的数据已有几十年了,但我仅扣除了100万个数据的最后7天。
非常感谢!
fig.add_trace(go.Scatter(
x=df_raw[df_raw[col_name]!=0].index,
y=[df_raw['Close'][j] for j in df_raw[df_raw[col_name]!=0].index],
mode='markers',
marker=dict(
size=8,
color='black',
symbol='cross'
),
name='Cdl Pattern'
))
I'm using pandas to plot a chart of stock data with datetime index in the dataframe. I'd like to plot black markers for rows where df_raw[col_name]!=0 but it is acting funky. When no dataframe rows meet the condition, the plot displays fine.
Can you help me understand what I'm doing wrong? Note that data for this stock is available for several decades, but I'm pulling only last 7 days of 1m data.
Thanks so much!
fig.add_trace(go.Scatter(
x=df_raw[df_raw[col_name]!=0].index,
y=[df_raw['Close'][j] for j in df_raw[df_raw[col_name]!=0].index],
mode='markers',
marker=dict(
size=8,
color='black',
symbol='cross'
),
name='Cdl Pattern'
))
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我可能已经找到了答案,并希望在此处发布它,以防它帮助他人。这是完整的绘图代码。请注意,它首先绘制“关闭”,然后绘制标记。
绘制“关闭”时,系统使用行号而不是索引,但是在绘制标记时,它明确指示使用索引。由于索引是DateTime,因此两个图最终都以不匹配的X轴。
为了纠正这一点,必须将X轴转换为我使用pd.series的行号。如果您知道的话,请建议一种更好的方法。
I may have found the answer and wanted to post it here in case it helps others. Here's the complete plotting code. Notice that it first plots the 'Close', and then the markers.
When plotting 'Close', the system uses row numbers instead of indices, but when plotting the markers, it is explicitly being directed to use indices. Since indices are Datetime, the two plots end up with mismatched x-axis.
To correct this, the x-axis had to be converted to row numbers for which I used pd.Series. Please suggest a better method if you know one.