Skip to content

Chart zooms in when new candlestick is made. #131

@JessevanVuuren

Description

@JessevanVuuren

when I have one row in my chart the candlesticks update as normal but when I plot 2 graphs it zooms automatically in.
how can I make the amount of candlesticks that you see on screen static/consistent

start:

Capture1

after a few candles:

Capture1

code to reporduse:

import finplot as fplt
import pandas as pd
import threading
import requests
import time


def startPlotting(symbol, limit, time):
    # 1m 3m 5m 15m 30m 1h 2h 4h 6h 8h 12h 1d 3d 1w 1M
    plots = []

    heikinAshiAx, candleAx = fplt.create_plot(f'Realtime: {symbol}, candlestick time: {time}', rows=2, init_zoom_periods=100, maximize=False)

    fplt.candle_bull_color = fplt.candle_bull_body_color = "#26a69a"
    fplt.candle_bear_color = fplt.candle_bear_body_color = "#ef5350"

    fplt.windows[0].ci.layout.setRowStretchFactor(0, 1)
    fplt.windows[0].ci.layout.setRowStretchFactor(1, 1)

    def heikinAshi(df):
        df['h_close'] = (df.open+df.close+df.high+df.low) / 4
        ho = (df.open.iloc[0] + df.close.iloc[0]) / 2
        for i,hc in zip(df.index, df['h_close']):
            df.loc[i, 'h_open'] = ho
            ho = (ho + hc) / 2
        df['h_high'] = df[['high','h_open','h_close']].max(axis=1)
        df['h_low'] = df[['low','h_open','h_close']].min(axis=1)

    def update():
        #request candlesticks
        table = requests.get(f"https://api.binance.com/api/v1/klines?symbol={symbol}&interval={time.lower()}&limit={limit}").json()
        df = pd.DataFrame(table, columns="time open high low close volume _ _ _ _ _ _".split()).drop(columns=["_"])
        df[["open", "high", "low", "close", "volume"]] = df[["open", "high", "low", "close", "volume"]].astype(float)

        #make heikinAshi candlesticks
        heikinAshi(df)

        # split up in candlestick
        heikinCandles = df['time h_open h_close h_high h_low'.split()]
        candlesticks = df['time open close high low'.split()]

        # debug info datafrane
        print(df.info())

        #plot candlesticks
        if not plots:
            plots.append(fplt.candlestick_ochl(candlesticks, ax=candleAx))
            plots.append(fplt.candlestick_ochl(heikinCandles, ax=heikinAshiAx))
        else:
            plots[0].update_data(candlesticks)
            plots[1].update_data(heikinCandles)

    update()
    fplt.timer_callback(update, 2)
    fplt.show()


startPlotting("BTCEUR", 300, "1m")

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions