furechan / mplchart

Classic Stock Charts in Python
MIT License
24 stars 6 forks source link

Display charts in streamlit app #5

Open vinaychuri opened 9 months ago

vinaychuri commented 9 months ago

We can view the plots in Jupyter notebooks via the following code.

indicators = [
    Candlesticks(),BBANDS(),Volume(), 
    RSI(),
]
with plt.style.context('classic'):
    chart = Chart(title="ticker", max_bars=200)
    chart.plot(df, indicators)

How to display the same in python streamlit app?

The above code + chart.show() does not work. The chart.plot() does not have any returnfig option.

furechan commented 9 months ago

Hi vinaychuri,

I am not familiar with streamlit, but I guess you could try to save the chart as svg with chart.render("svg") and use the svg output. See scripts/make-showcase.ipynb for an example.

ambideXtrous9 commented 2 months ago

I am also facing the same issue.

furechan commented 2 months ago

Hi @ambideXtrous9,

Not a streamlit user here, but it seems you can plot the chart in streamlit by calling st.pyplot(chart.figure) as in the following snippet.

chart = Chart(title=ticker, max_bars=max_bars)
chart.plot(prices, indicators)
st.pyplot(chart.figure)

I added an example mplchart-streamlit.py in the examples folder.