Pandas 和 matplotlib - 在折线图上绘制散点图

兄弟

我正在构建一个交易机器人,目前正在回测。我有两个 Pandas DataFrame,一个比另一个长得多。较长的包含 x 年的所有日期和所有索引。另一个数据框只包含我买入或卖出的日期和索引。

Long_frame = {'date':['2020-01-10', '2020-01-11', '2020-01-12', '2020-01-13', '2020-01-14', '2020-01-15'], 'index': [2, 4, 6, 8, 10, 20]}
Short_frame = {'date':['2020-01-10', '2020-01-11', '2020-01-13', '2020-01-15'], 'index': [2, 4, 8, 20]}

当我尝试在同一张图上绘制此图时,短列表的线或散点最终在图的开头非常紧凑。我应该如何绘制这个以获得有意义的图表?最佳的图形是只有一条线,一条长线,并在交易发生的那条线上绘制点。

谢谢!

您可以使用 x 轴的日期:

Long_frame = {'date':['2020-01-10', '2020-01-11', '2020-01-12', '2020-01-13', '2020-01-14', '2020-01-15'],'index': [2, 4, 6, 8, 10, 20]}
Short_frame = {'date':['2020-01-10', '2020-01-11', '2020-01-13', '2020-01-15'], 'index': [2, 4, 8, 20]}


import matplotlib.pyplot as plt

plt.plot(Long_frame['date'], Long_frame['index'])
plt.plot(Short_frame['date'], Short_frame['index'],'.', markersize=15)

交易日期点位于日期位置,两个图表均“均匀分布”

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

使用pandas和matplotlib绘制叠加图(折线图和条形图)

使用 pandas 和 matplotlib 的分组折线图

Matplotlib ylim和xlim无法在散点图和折线图或fill_between之间组合使用

Matplotlib:绘制折线图设置线型、比例和自定义颜色

使用pandas和matplotlib绘制多条线图

使用matplotlib的图例和折线图标题

Python-在matplotlib中绘制带有日期时间的折线图和带有NaN值的列

如何使用Google图表在同一图形上绘制散点图和折线图

如何在 Python 中使用 Plotly 在同一图表上绘制散点图和折线图?

在散点图上绘制折线图

如何在条形图和折线图的同一图上绘制多个列表?

Matplotlib和Pandas在同一图上绘制的图

参数尺寸在 matplotlib 折线图上不兼容

从折线图在matplotlib中绘制平均值?

Python Matplotlib如何以每周间隔绘制折线图

如何在折线图上隐藏和显示点

使用pandas和matplotlib绘制分类数据

使用 pandas 和 matplotlib 绘制宽数据

用Pandas和Matplotlib绘制groupby

matplotlib中的折线图

Matplotlib 折线图动画

Pandas / Matplotlib-从多个DataFrame列中平滑折线图

从Pandas数据框中绘制折线图(多条线)

创建带有多条线和图例的 Matplotlib 折线图

用Pandas和Matplotlib绘制Candlestick_OHLC一分钟柱线图

无法使用pandas plot()函数组合条形图和折线图

在 Python pandas 中对齐折线图和条形图

pandas DataFrame如何混合不同比例的条形图和折线图

使用Seaborn和Matplotlib在热图和折线图的共享子图中对齐x轴刻度