How can I put two charts on the same figure?

Summary

I want to put a bar graph under the line chart on same figure.

Code snippet:

import yfinance as yf
import streamlib as st
historical_data = yf.Ticker("AAPL").history(period="5y")
st.header("Stock Data for {}".format(ticker))
st.subheader("Latest Day")

latest_day_data = historical_data.iloc[-1].Close
st.text(f"Price: ${latest_day_data:.2f}")

st.subheader("Historical Data")
st.line_chart(historical_data["Close"])

volume = historical_data.Volume
st.bar_chart(volume)

Expected behavior:

Two graphs must be on same figure like Tradingview as shown below:
Screenshot from 2022-12-18 21-33-47

Actual behavior:

The plots are on seperate charts as shown in image below:

Debug info

  • Streamlit version: 1.16.0
  • Python version: 3.10.8
  • Using Conda
  • OS version: Ubuntu 22.10

Requirements file

conda
yfinance
streamlit

If you need to customize your charts, use one of the supported libraries to build it and pass the customized chart to Streamlit. st.line_chart and st.bar_chart are just basic, unmodified Altair charts, but Streamlit supports other libraries too. You could use Altair, Plotly, Matplotlib…whichever you prefer.