【问题标题】:Adding lines and geometric shapes on matplotlib candlestick chart在 matplotlib 烛台图上添加线条和几何形状
【发布时间】:2017-09-04 19:06:22
【问题描述】:

我使用matplotlib.finance 在 python 上制作了烛台货币图表。一切正常,但我想在实际图表上添加线条和形状。当我在 matplotlib 中使用普通类型的图表时。我会这样做:

plt.plot([xmin, xmax], [0.0005,0.0005], linewidth=3, color='purple')

在 0.0005 的价格水平上从xminxmax(待定义)画一条水平线。但是由于我使用的是candlestick2_ohlc 方法,我真的不知道如何进行...

这就是我所拥有的:

这就是我想要得到的:

也可以绘制和填充三角形吗?

【问题讨论】:

    标签: python matplotlib candlestick-chart


    【解决方案1】:

    绘制水平线最简单的方法是使用

    plt.axhline(y=1.066)
    

    【讨论】:

    • 谢谢,你知道画线段和三角形的方法吗?
    • 一般来说,你可以画出this example所示的形状。三角形是RegularPolygon
    【解决方案2】:

    绘制线段

    plt.plot([xmin, xmax], [ymin, ymax])
    

    绘制三角形

    x = [x1, x2]
    y = [y1, y2]
    plt.fill(x,y)
    

    绘制多边形

    x = [x1,...,xn]
    y = [y1,...,yn]
    plt.fill(x,y)
    

    就这么简单!

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-08-19
      • 1970-01-01
      • 2023-04-04
      • 1970-01-01
      • 1970-01-01
      • 2015-05-09
      相关资源
      最近更新 更多