chrisvnz commited on
Commit
b04d361
·
1 Parent(s): b39ade6

Update app.py

Browse files

Replaced matplotlib with plotly for better visualisation

Files changed (1) hide show
  1. app.py +8 -11
app.py CHANGED
@@ -1,6 +1,6 @@
 
1
  import streamlit as st
2
  import yfinance as yf
3
- import matplotlib.pyplot as plt
4
  import pandas as pd
5
  import numpy as np
6
  from urllib.request import urlopen, Request
@@ -194,6 +194,7 @@ if uploaded_file is not None:
194
  # Display the sector mapping table
195
  st.table(pd.DataFrame(list(sector_mapping.items()), columns=['ETF', 'Sector']))
196
 
 
197
  if st.button('Submit'):
198
  # Get trends
199
  stock_trend = get_trend(ticker)
@@ -205,13 +206,11 @@ if uploaded_file is not None:
205
  sector_trend = pd.DataFrame(scaler.fit_transform(sector_trend.values.reshape(-1,1)), index=sector_trend.index, columns=['Close'])
206
 
207
  # Plot trends
208
- plt.figure(figsize=(12,6))
209
- plt.plot(stock_trend.index, stock_trend.values, label=ticker)
210
- plt.plot(sector_trend.index, sector_trend.values, label=sector)
211
- plt.legend()
212
- plt.grid(True)
213
- plt.title('Stock and Sector Trend over the past 30 days')
214
- st.pyplot(plt)
215
 
216
  st.subheader("Hourly and Daily Sentiment of {} Stock".format(ticker))
217
  news_table = get_news(ticker)
@@ -248,6 +247,4 @@ footer {visibility: hidden;}
248
  """
249
  st.markdown(hide_streamlit_style, unsafe_allow_html=True)
250
 
251
-
252
-
253
- # streamlit run "c:/Dropbox/BIMWERX/_work/YouTube/elephant/230701-10 - ML Predict/src/trend_sentiment.py"
 
1
+ import plotly.graph_objects as go
2
  import streamlit as st
3
  import yfinance as yf
 
4
  import pandas as pd
5
  import numpy as np
6
  from urllib.request import urlopen, Request
 
194
  # Display the sector mapping table
195
  st.table(pd.DataFrame(list(sector_mapping.items()), columns=['ETF', 'Sector']))
196
 
197
+
198
  if st.button('Submit'):
199
  # Get trends
200
  stock_trend = get_trend(ticker)
 
206
  sector_trend = pd.DataFrame(scaler.fit_transform(sector_trend.values.reshape(-1,1)), index=sector_trend.index, columns=['Close'])
207
 
208
  # Plot trends
209
+ fig = go.Figure()
210
+ fig.add_trace(go.Scatter(x=stock_trend.index, y=stock_trend['Close'], mode='lines', name=ticker))
211
+ fig.add_trace(go.Scatter(x=sector_trend.index, y=sector_trend['Close'], mode='lines', name=sector))
212
+ fig.update_layout(title='Stock and Sector Trend over the past 30 days', xaxis_title='Date', yaxis_title='Normalized Close Price', autosize=False, width=2000, height=1200)
213
+ st.plotly_chart(fig)
 
 
214
 
215
  st.subheader("Hourly and Daily Sentiment of {} Stock".format(ticker))
216
  news_table = get_news(ticker)
 
247
  """
248
  st.markdown(hide_streamlit_style, unsafe_allow_html=True)
249
 
250
+ # streamlit run "c:/Dropbox/BIMWERX/_work/YouTube/elephant/230701-10 - ML Predict/src/stock_sentiment2.py"