import streamlit as st import pandas as pd import numpy as np import yfinance as yf import altair as alt import plotly.figure_factory as ff import pydeck as pdk from vega_datasets import data as vds import plotly.express as px import plotly.graph_objects as go from plotly.subplots import make_subplots from streamlit_image_comparison import image_comparison def on_input_change(): user_input = st.session_state.user_input st.session_state.past.append(user_input) st.session_state.generated.append( {"data": "The messages from Bot\nWith new line", "type": "normal"} ) def on_btn_click(): del st.session_state.past[:] del st.session_state.generated[:] def main(): st.title(" All Graphs") ( col1, col2, ) = st.columns(2) with col1: st.line_chart( pd.DataFrame( { "Apple": yf.download("AAPL", start="2023-01-01", end="2023-07-31")[ "Adj Close" ], "Google": yf.download( "GOOGL", start="2023-01-01", end="2023-07-31" )["Adj Close"], "Microsoft": yf.download( "MSFT", start="2023-01-01", end="2023-07-31" )["Adj Close"], } ) ) with col2: data = pd.DataFrame( {"X": [1, 2, 3, 4, 5], "Y1": [10, 16, 8, 14, 12], "Y2": [5, 8, 3, 6, 7]} ) st.area_chart(data) st.plotly_chart( ff.create_distplot( [np.random.randn(200) - 2, np.random.randn(200), np.random.randn(200) + 2], ["Negative Shift", "Normal", "Positive Shift"], bin_size=[0.1, 0.25, 0.5], ), use_container_width=True, ) source = vds.cars() chart = { "mark": "point", "encoding": { "x": {"field": "Horsepower", "type": "quantitative"}, "y": {"field": "Miles_per_Gallon", "type": "quantitative"}, "color": {"field": "Origin", "type": "nominal"}, "shape": {"field": "Origin", "type": "nominal"}, }, } tab1, tab2 = st.tabs(["Streamlit theme (default)", "Vega-Lite native theme"]) with tab1: st.vega_lite_chart(source, chart, theme="streamlit", use_container_width=True) with tab2: st.vega_lite_chart(source, chart, theme=None, use_container_width=True) st.altair_chart( alt.Chart( pd.DataFrame( { "x": np.random.rand(50), "y": np.random.rand(50), "size": np.random.randint(10, 100, 50), "color": np.random.rand(50), } ) ) .mark_circle() .encode( x="x", y="y", size="size", color="color", tooltip=["x", "y", "size", "color"], ) .properties(width=600, height=400), use_container_width=True, ) st.bar_chart( pd.DataFrame(np.random.randn(20, 3), columns=["Apple", "Banana", "Cherry"]) ) st.pydeck_chart( pdk.Deck( map_style=None, initial_view_state=pdk.ViewState( latitude=37.76, longitude=-122.4, zoom=11, pitch=50 ), layers=[ pdk.Layer( "HexagonLayer", data=pd.DataFrame( np.random.randn(1000, 2) / [50, 50] + [37.76, -122.4], columns=["lat", "lon"], ), get_position="[lon, lat]", radius=200, elevation_scale=4, elevation_range=[0, 1000], pickable=True, extruded=True, ), pdk.Layer( "ScatterplotLayer", data=pd.DataFrame( np.random.randn(1000, 2) / [50, 50] + [37.76, -122.4], columns=["lat", "lon"], ), get_position="[lon, lat]", get_color="[200, 30, 0, 160]", get_radius=200, ), ], ) ) import datetime np.random.seed(1) programmers = ["Alex", "Nicole", "Sara", "Etienne", "Chelsea", "Jody", "Marianne"] base = datetime.datetime.today() dates = base - np.arange(180) * datetime.timedelta(days=1) z = np.random.poisson(size=(len(programmers), len(dates))) fig = go.Figure(data=go.Heatmap(z=z, x=dates, y=programmers, colorscale="Viridis")) fig.update_layout(title="GitHub commits per day", xaxis_nticks=36) st.plotly_chart(fig) ( col1, col2, ) = st.columns(2) with col1: df = px.data.gapminder().query("year == 2007").query("continent == 'Americas'") fig = px.pie( df, values="pop", names="country", title="Population of American continent", hover_data=["lifeExp"], labels={"lifeExp": "life expectancy"}, ) fig.update_traces(textposition="inside", textinfo="percent+label") st.plotly_chart(fig) with col2: fig = go.Figure( go.Sunburst( labels=[ "Eve", "Cain", "Seth", "Enos", "Noam", "Abel", "Awan", "Enoch", "Azura", ], parents=["", "Eve", "Eve", "Seth", "Seth", "Eve", "Eve", "Awan", "Eve"], values=[10, 14, 12, 10, 2, 6, 6, 4, 4], ) ) fig.update_layout(margin=dict(t=0, l=0, r=0, b=0)) st.plotly_chart(fig) if __name__ == "__main__": main()