I just don't know who to ask….
Everything in the program works, but there is one annoying thing.
Doesn't clear axes[2] during animation. I don't understand what's wrong.
ax_hisg this is an indicator BuySell Volume.
When removing the first elements(candles, volumes, BuySell Volumes)
the first indicator value BuySell remains in place. I want to understand why.
`
import datetime
import pandas as pd
import time
import mplfinance as mpf
import matplotlib.animation as animation
I just don't know who to ask…. Everything in the program works, but there is one annoying thing. Doesn't clear axes[2] during animation. I don't understand what's wrong. ax_hisg this is an indicator BuySell Volume. When removing the first elements(candles, volumes, BuySell Volumes) the first indicator value BuySell remains in place. I want to understand why.![screen](https://github.com/matplotlib/mplfinance/assets/104761481/183a61a5-1c6c-4835-a9c7-78dcfe09bb46)
` import datetime import pandas as pd import time import mplfinance as mpf import matplotlib.animation as animation
pd.options.mode.chained_assignment = None constVolume = 100000000 # объём собираемых свечей в деньгах t_begin = datetime.datetime(2023, 11, 22, 14, 30, 0, 0) delta = datetime.timedelta(seconds=30) fin = pd.read_csv('/home/home/PycharmProjects/pythonProject/AAPL.csv', parse_dates=True) fin['Date'] = fin['Date'].astype("datetime64[ns]") df0 = pd.DataFrame(columns=['Date', 'Open', 'Close', 'High', 'Low', 'Volume', 'Buy', 'Sell'], dtype=float) df0['Date'] = df0['Date'].astype("datetime64[ns]")
def copy_ticks_range(t_begin, t_current, fin)
def make_candles(df_ticks, constVolume, df0):
t_current = t_begin + delta df_ticks = copy_ticks_range(t_begin, t_current, fin) t_begin = t_current df0 = make_candles(df_ticks, constVolume, df0) print(df0)
bs_calc = df0['Buy'] - df0['Sell'] apds = [mpf.make_addplot(bs_calc, panel=1, color='b', type='bar', width=0.5, alpha=1, secondary_y=True)]
fig, axes = mpf.plot(df0, type='candle', addplot=apds, figscale=1.5, figratio=(7, 5), title='\n\nAAPL', scale_padding={'left': 0.31, 'top': 0.1, 'right': 0.21, 'bottom': 0.3}, style='starsandstripes', volume=True, volume_panel=2, panel_ratios=(12, 3, 1), returnfig=True)
ax_main = axes[0] ax_hisg = axes[2] ax_volu = axes[4]
def animate(ival): global t_begin, df0 t_current = t_begin + delta df_ticks = copy_ticks_range(t_begin, t_current, fin) t_begin = t_current df0 = make_candles(df_ticks, constVolume, df0) bs_calc = df0['Buy'] - df0['Sell'] apds = [mpf.make_addplot(bs_calc, panel=1, color='b', type='bar', width=0.5, alpha=1, secondary_y=True, ax=ax_hisg)] print(df0) data = df0.iloc[0:(20 + ival)] if len(data) > 4: df0.drop(index=data.index[0], axis=0, inplace=True) ax_main.clear() ax_hisg.clear() ax_volu.clear() mpf.plot(data, type='candle', addplot=apds, ax=ax_main, volume=ax_volu)
ani = animation.FuncAnimation(fig, animate, cache_frame_data=False) mpf.show() time.sleep(1) `