I need to create a plot that is basically a candlestick plot, but I need the upper and lower shadows to be as thick as the body, instead of the typical lines. I suppose I could plot it with matplotlib, but I have no clue how to do it. I tried with mplfinance but there is no way to define the thickness of the shadows.
Do you have any idea? The original dataset is the typical from yfinance, an index with datetime and columns 'open','close','high','low'.
Thanks for the support.
Is THIS what you are looking to do?
If so, forget my previous answer about the the "widths" tutorial. The problem with that approach is that the candle_linewidth
parameter affects both the wick (shadow) and the edge of the candle body. So making the wick (shadow) wider also makes the edge of the candle body itself wider.
The way to make a plot like the above is to plot two sets of candlesticks, one regular (mpf.plot()
) and the other using mpf.make_addplot()
.
The data is the same for both sets except for the regular mpf.plot()
you copy the High's and Low's over the Open's and Close's so that the candle body (which uses Open and Close) will actually extend as far as the High and Low.
Given an OHLC dataframe, df1
, do the following:
# First create an identical, separate dataframe:
df2 = df1.copy()
# Then, in the newly created dataframe,
# copy the High and Low over the Open and Close:
df2['Open'] = df2['High']
df2['Close'] = df2['Low']
# Plot both;
# The original dataframe MUST BE in the addplot:
ap = mpf.make_addplot(df1,type='candle')
mpf.plot(df2,type='candle',addplot=ap)
This works well for Black and White candles as you can see above. But for some of the mplfinance styles, the wick/shadow color can be seen through the candle body, for example:
ap = mpf.make_addplot(df1,type='candle')
mpf.plot(df2,type='candle',addplot=ap,style='blueskies')
This can be fixed by making the wick color match the down candle color, for example:
mc = mpf.make_marketcolors(base_mpf_style='blueskies')
mc['wick'][ 'up' ] = mc['candle']['down']
mc['wick']['down'] = mc['candle']['down']
custom_style = mpf.make_mpf_style(base_mpf_style='blueskies',marketcolors=mc)
ap = mpf.make_addplot(df1,type='candle')
mpf.plot(df2,type='candle',addplot=ap,style=custom_style)