[Python] matplotlib candlestick chart and multiple subplots

Discussão em 'Python' iniciado por Stack, Março 22, 2025.

  1. Stack

    Stack Membro Participativo

    I need candlestick chart in one subplot and another subplot which share Y axe with candlestick chart.
    I have following code drawing subplots:

    df = get_current_data(limit=150)
    df_asks, df_bids = get_order_book_data(bookStep="step0",limit=150)
    fig, ((ax1, ax2),(ax3,ax4)) = plt.subplots(2,2, sharex='col', sharey='row', width_ratios=[5,1], height_ratios=[5,1])
    ax1.plot(df["timestamp"],df["close"])
    ax2.plot(df_asks["amount"],df_asks["price"],"r")
    ax2.plot(df_bids["amount"],df_bids["price"],"g")
    ax3.bar(df["timestamp"],df["volume"], width=0.0005)
    plt.subplots_adjust(wspace=0.0,hspace=0.0)
    ax1.set_title("BTC USD")
    ax2.set_title("Orders Book")
    ax1.set_ylabel("Price")
    ax3.set_ylabel("Volume")
    ax1.grid()
    ax2.grid()
    plt.show()


    Result: [​IMG]

    I need instead of BTC line to draw candlesticks.
    I know i can use mplfinance library to draw candlestick chart, but seems to be mplfinance allows to stack additional subplots ONLY vertically sharing X (index of DataFrame which is datetime).

    Continue reading...

Compartilhe esta Página