How to make color the wick portion of a candlestick stick using matplotlib?

后端 未结 2 1098
清歌不尽
清歌不尽 2021-01-28 07:21

I\'m looking to make the wick portion of a candlestick stick black using matplotlib? I couldn\'t find any mention of it in the documentation, but I\'ve seen pictoral examples sh

2条回答
  •  不要未来只要你来
    2021-01-28 08:20

    Rewriting the complete candlestick_ohlc seems overly complicated. You can just iterate over the lines returned by the function and set their color to black. You may also set the zorder to have the wicks appear below the boxes.

    lines, patches = candlestick_ohlc(ax, quotes, width=0.5)
    for line, patch in zip(lines, patches):
        patch.set_edgecolor("k")
        patch.set_linewidth(0.72)
        patch.set_antialiased(False)
        line.set_color("k")
        line.set_zorder(0)
    

    If this is to be used often in a script, you can of course put it in a function.

    def candlestick_ohlc_black(*args,**kwargs):
        lines, patches = candlestick_ohlc(*args,**kwargs)
        for line, patch in zip(lines, patches):
            patch.set_edgecolor("k")
            patch.set_linewidth(0.72)
            patch.set_antialiased(False)
            line.set_color("k")
            line.set_zorder(0)
    
    candlestick_ohlc_black(ax, quotes, width=0.5)
    

提交回复
热议问题