Sitemap

Member-only story

Plotly in Streamlit_1

5 min readDec 18, 2024

--

Hello Guys,

Press enter or click to view image in full size
generated in leonardo.ai

Basic Example: Scatter Plot

python
Copy code
import streamlit as st
import plotly.express as px
import pandas as pd
# Streamlit app title
st.title("Interactive Plotly Visualizations in Streamlit")
# Example DataFrame
data = {
'Category': ['A', 'B', 'C', 'D'],
'Value1': [10, 20, 30, 40],
'Value2': [15, 25, 35, 45]
}
df = pd.DataFrame(data)
# Plotly scatter plot
fig = px.scatter(df, x='Value1', y='Value2', color='Category', title="Scatter Plot Example")
# Display Plotly chart in Streamlit
st.plotly_chart(fig)

Bar Chart with User Input

python
Copy code
import streamlit as st
import plotly.express as px
import pandas as pd
# App title
st.title("Interactive Bar Chart with Plotly")
# Example DataFrame
data = {
'Product': ['Product A', 'Product B', 'Product C', 'Product D'],
'Sales': [100, 150, 200, 250]
}
df = pd.DataFrame(data)
# User input for bar chart customization
selected_color = st.selectbox("Choose a color for the bars:", ["Blue", "Green", "Red"])

--

--