I am using matplotlib finance (mpfinance) and am currently having weird intermittent plotting problems with it. (There are no tags for it within stack overflow so it's challenging to flag properly:
This isn't displaying the proper plot. Removing addplot = ap
doesn't change this image.
However, the same code with a different ticker dataframe works below (they are in the same exact format)
# Plotting call ratio with close price and volume
ap = mpf.make_addplot((TSLA_df['call_ratio']), panel = 1, color = 'black', linestyle = 'dotted', ylabel = 'Call volume %')
mpf.plot(TSLA_df,
type = 'candle',
volume = True,
addplot = ap,
style = 'binance',
ylabel = 'TSLA share price',
ylabel_lower = 'Call Volume')
Which produces:
They are both pulling data mentioning that specific ticker from the dataframe, and there are no NaN's, so I have no clue why it isn't working. I am trying to get the dashed line on y axis the bottom of the lower box. I guess I'm struggling to figure out why the same code is not working for a specific plot, and wondered if this type of issue was with my code of matplotlib finance.
If anyone has any ideas as to why this would be happening, they'd be greatly appreciated.
Sample df:
date ticker call_volume call_ratio open low high close volume
2021-03-08 AAPL 1229656 0.5782918149466192 120.93 116.209999 121.0 116.360001 154376600.0
2021-03-09 AAPL 774465 3.357156230430039 119.029999 118.790001 122.059998 121.089996 129525800.0
2021-03-10 AAPL 447447 3.9110777365810923 121.690002 119.449997 122.16999799999999 119.980003 111943300.0
2021-03-11 AAPL 577996 1.730115779347954 122.540001 121.260002 123.209999 121.959999 103026500.0
2021-03-12 AAPL 884787 0.5651077603988305 120.400002 119.160004 121.16999799999999 121.029999 88105100.0
2021-03-15 AAPL 778816 1.0272002629632673 121.410004 120.41999799999999 124.0 123.989998 92403800.0
2021-03-16 AAPL 1398777 1.8768538516146607 125.699997 124.720001 127.220001 125.57 115227900.0
2021-03-17 AAPL 978950 0.30645078911078194 124.050003 122.339996 125.860001 124.760002 111932600.0
2021-03-18 AAPL 1041143 2.7229688909208436 122.879997 120.32 123.18 120.529999 121229700.0
2021-03-19 AAPL 1123895 2.2817967870664075 119.900002 119.68 121.43 119.989998 185549500.0
CodePudding user response:
You may want to print out your data arguments to make_addplot()
and plot()
calls, just before the call, to be absolutely certain that the following assumption holds ...
Assuming that your data has not changed as a result of:
I had this code working earlier tonight and displaying the 2 correct y labels/axis, and changed relatively nothing of importance ...
then it is very likely that the problem will be fixed by adding secondary_y=True
in your call to mpf.make_addplot()
.