Plotting a Swing chart over the generic OHLC chart
还没有人认领这个 Issue。
评估
- 难度
- 4/5
- 预计耗时
- 3-5 天
- 新手友好度
- 35/100
- Issue 类型
- 功能
- 描述清晰度
- 基本清楚
- 活跃度
- 停滞
- 技术栈
- python
调研方向
从示例中的 mpf.plot 和 mpf.make_addplot 调用开始,然后使用所述的 daily 和 swing DataFrames 重现不匹配问题。跟踪 addplot 数据如何与 OHLC x 轴对齐;完成的标准是:稀疏的 swing 序列可以叠加到普通 OHLC 图表上,不出现 x/y 维度错误,并且符合所要求的 swing 可视化效果。
由索引模型根据 Issue 内容生成。
描述
I'm want to visualize a swings/price movement chart over a normal OHLC chart, e.g., like the attachment below.

I have written the following code:
def get_swing_dataframe(daily: DataFrame):
last_high = -999999999
last_low = abs(last_high)
raw_dftb = []
dip = True
for row in daily.iterrows():
close = row[1]["Close"]
mark = False
if dip:
if close > last_high:
dip = False
mark = True
last_high = close
else:
if close < last_low:
dip = True
mark = True
last_low = close
if mark:
raw_dftb.append(row[1])
df = pd.DataFrame(raw_dftb)
df.index.name = "Date"
return df
def main():
daily = pd.read_csv("ES___CCB.csv", index_col=0, parse_dates=True)
daily.index.name = "Date"
swing = get_swing_dataframe(daily)
mpf.plot(
daily,
style="binance",
type="ohlc",
addplot=[mpf.make_addplot(swing, type="line", color="g", panel=1)],
)
if __name__ == "__main__":
main()
The issue here is that the "Swing" dataframe does not have a data entry for every single date, it only marks where and when the price changes, spitting out the following error:
File "D:\Andaconda3\lib\site-packages\matplotlib\axes\_axes.py", line 1605, in plot
lines = [*self._get_lines(*args, data=data, **kwargs)]
File "D:\Andaconda3\lib\site-packages\matplotlib\axes\_base.py", line 315, in __call__
yield from self._plot_args(this, kwargs)
File "D:\Andaconda3\lib\site-packages\matplotlib\axes\_base.py", line 501, in _plot_args
raise ValueError(f"x and y must have same first dimension, but "
ValueError: x and y must have same first dimension, but have shapes (6232,) and (23,)
How can I achieve this?
Recap: I want to visualize a swings/price movement chart over a normal OHLC chart, e.g., like the attachment below.
- 主要语言
- Python
- 星标
- 4.4k
- 派生
- 677
- PR 合并指标
- 30 天内没有已合并 PR
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 没有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
matplotlib/mplfinance 的其他 Issue
-
Bug Report: Errors occur for NaN columns.可能重新可做 关联的 PR 已关闭且未合并。 未关闭bug
难度 2/5 1-3 小时 新手友好度 62/100
matplotlib/mplfinance#672 ·
-
难度 5/5 一周以上 新手友好度 10/100
matplotlib/mplfinance#700 ·
-
enhancement
难度 5/5 一周以上 新手友好度 30/100
matplotlib/mplfinance#695 ·
-
question
难度 3/5 1-2 天 新手友好度 25/100
matplotlib/mplfinance#691 · 1 条评论 ·
-
question
难度 4/5 3-5 天 新手友好度 52/100
matplotlib/mplfinance#690 · 5 条评论 ·
查看 matplotlib/mplfinance 的全部 Issue
相似的 Issue
-
Agentic
难度 2/5 1-3 小时 新手友好度 72/100
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 82/100
Imbad0202/academic-research-skills#979 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 72/100
reflex-dev/reflex#7561 · 1 条评论 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 72/100
-
难度 2/5 1-3 小时 新手友好度 62/100
prometheus-community/ansible#906 · 2 条评论 ·