python - 如何在 Pandas 数据系列上绘制任意标记?

标签 python matplotlib pandas

我正在尝试在 pandas 数据系列中放置标记(以在股票市场图表上显示买入/卖出事件)

我可以在使用 pyplot 创建的简单数组上执行此操作,但是我找不到关于如何在 Pandas 时间序列中指示任意事件的引用。

也许 pandas 没有内置此功能。有人可以按照这个系列的方式提供帮助并沿着曲线添加一些任意标记...

import datetime
import matplotlib.pyplot as plt
import pandas
from pandas import Series, date_range
import numpy as np
import random



ts = Series(randn(1000), index=date_range('1/1/2000', periods=1000))
ts = ts.cumsum()

#--  the markers should be another pandas time series with true/false values
#--    We only want to show a mark where the value is True
tfValues = np.random.randint(2, size=len(ts)).astype('bool')
markers = Series(tfValues, index=date_range('1/1/2000', periods=1000))

fig, ax1 = plt.subplots()
ts.plot(ax=ax1)

ax1.plot(markers,'g^')   # This is where I get held up.
plt.show()

最佳答案

使用选项

ts.plot(marker='o')

ts.plot(marker='.')

关于python - 如何在 Pandas 数据系列上绘制任意标记?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19939084/

相关文章:

python - Web 抓取 LinkedIn 没有给我 html...。我做错了什么?

python - 将循环 block 转换为列表理解

python - 如何用matplotlib制作 'fuller'轴箭头

python - Matplotlib tight_layout 导致 RuntimeError

python - Pandas - 滚动斜率计算

python - 如何删除所有重复出现或在 Pandas 数据框中获取唯一值?

Python 循环中 for 错误检查的习惯用法

python - 先填一个matplotlib图例的右栏

Python - 不确定如何将列中的行值汇总到列表中

python - Fabric "TypeError: not all arguments converted during string formatting"