【问题标题】:Matplotlib line time series with scatter带散点的 Matplotlib 线时间序列
【发布时间】:2021-09-03 14:36:51
【问题描述】:

我正在努力使用 python、pandas 和 matplotlib 制作质量图表。目标是制作一个基于时间的漂亮折线图,然后基于布尔值,使用某种指标(可能是顶部的散点图)显示是否为 TRUE。

现在,它正在发生,但很难看到它,因为圆圈会覆盖线。时间范围也可以更改为 1 年或 5 年,因此点必须进行调整。此外,图例未显示。

def plot_stock(stock_prices_bollinger, ticker):
    plt.title(ticker)
    # y label
    plt.ylabel('stock price')
    # and a legend
    plt.legend(loc='upper right')
    plt.plot(stock_prices_bollinger['Price'])
    return plt.scatter(
        stock_prices_bollinger.index,
        stock_prices_bollinger['Price'],
        c=stock_prices_bollinger['breakout'])

然后调用函数如下:

ticker = 'MMM'
from_date = '2011-01-01'
to_date = '2016-10-01'

Prices = stock_info(ticker, pd.to_datetime(from_date, format='%Y-%m-%d'), 
pd.to_datetime(to_date, format='%Y-%m-%d'))
Prices_breakout = bollinger(Prices)
plot_stock(Prices_breakout, ticker)

【问题讨论】:

  • 您的 plt.plot 和 plt.scatter 中没有任何标签,因此未显示图例。

标签: python matplotlib


【解决方案1】:

对此我没有具体答案,但如果您尝试使用 Pandas 和 matplotlib 绘制股票价格,您可能会发现此链接很有帮助:

https://ntguardian.wordpress.com/2016/09/19/introduction-stock-market-data-python-1/

去年我在尝试熟悉 pandas 时浏览了它,我认为它确实提供了丰富的信息。

【讨论】:

    猜你喜欢
    • 2021-05-08
    • 1970-01-01
    • 2017-03-31
    • 1970-01-01
    • 1970-01-01
    • 2017-09-13
    • 1970-01-01
    • 1970-01-01
    • 2020-09-21
    相关资源
    最近更新 更多