ApTinyPle
ApTinyPle

Reputation: 1

Candlestick plot with matplotlib

I plot a candlestick chart with python 3 using matplotlib. There is one thing that looks not as I would like. It's lines in candles body (see the image below). Thus the question:

Is there a way to avoid their presence? Also, I need to keep the black/white style.

enter image description here

Upvotes: 0

Views: 3598

Answers (2)

Jonas Byström
Jonas Byström

Reputation: 26189

I developed finplot, to get a better API and higher performance. finplot does not have this rendering bug on hollow candles by default.

import finplot as fplt
import yfinance as yf

df = yf.download('AAPL', '2020-05-01')

ax,axv = fplt.create_plot('Apple Inc.', rows=2)
cplot = fplt.candlestick_ochl(df[['Open','Close','High','Low']], ax=ax)
vplot = fplt.volume_ocv(df[['Open','Close','Volume']], ax=axv)

cplot.colors.update(dict(bull_frame='#000', bull_body='#fff', bull_shadow='#000', bear_frame='#000', bear_body='#000', bear_shadow='#000'))
vplot.colors.update(dict(bull_frame='#000', bull_body='#fff', bear_frame='#000', bear_body='#000'))

fplt.show()

finplot b/w

Upvotes: 2

ImportanceOfBeingErnest
ImportanceOfBeingErnest

Reputation: 339775

As seen e.g. in this answer, you can obtain the lines and patches of the candlestick graph and change their properties to your likings:

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) # make lines appear behind the patches
    line.set_visible(False) # make them invisible

Upvotes: 2

Related Questions