Create a collection of the most bieutiful plotly plot you can generate. A those should be display in a streamlit application
To upload files, please first save the app
import streamlit as st
import plotly.express as px
import plotly.graph_objects as go
import numpy as np
import pandas as pd
from plotly.subplots import make_subplots
st.set_page_config(layout="wide")
st.title("Advanced Plotly Visualizations Showcase")
# Generate sample data
np.random.seed(42)
dates = pd.date_range(start='2023-01-01', end='2023-12-31', freq='D')
values = np.random.normal(0, 1, size=len(dates)).cumsum()
df = pd.DataFrame({
'date': dates,
'value': values,
'category': np.random.choice(['A', 'B', 'C'], size=len(dates)),
'size': np.random.randint(10, 100, size=len(dates))
})
# 1. 3D Surface Plot
st.header("1. 3D Surface Plot")
X = np.linspace(-5, 5, 100)
Y = np.linspace(-5, 5, 100)
X, Y = np.meshgrid(X, Y)
Z = np.sin(np.sqrt(X**2 + Y**2))
fig_surface = go.Figure(data=[go.Surface(z=Z, x=X, y=Y)])
fig_surface.update_layout(
title='3D Surface Plot of sin(sqrt(x² + y²))',
autosize=False,
width=800,
height=600,
scene=dict(
camera=dict(
up=dict(x=0, y=0, z=1),
center=dict(x=0, y=0, z=0),
eye=dict(x=1.5, y=1.5, z=1.5)
)
)
)
st.plotly_chart(fig_surface)
# 2. Animated Bubble Chart
st.header("2. Animated Bubble Chart")
bubble_df = px.data.gapminder()
fig_bubble = px.scatter(
bubble_df,
x="gdpPercap",
y="lifeExp",
animation_frame="year",
animation_group="country",
size="pop",
color="continent",
hover_name="country",
log_x=True,
size_max=55,
range_x=[100, 100000],
range_y=[25, 90],
title="GDP per Capita vs Life Expectancy (1952-2007)"
)
st.plotly_chart(fig_bubble)
# 3. Sunburst Chart
st.header("3. Sunburst Chart")
fig_sunburst = px.sunburst(
px.data.tips(),
path=['day', 'time', 'sex'],
values='total_bill',
title="Restaurant Tips Analysis"
)
st.plotly_chart(fig_sunburst)
# 4. Candlestick Chart with Range Slider
st.header("4. Candlestick Chart with Range Slider")
df_stocks = pd.DataFrame({
'Date': pd.date_range(start='2023-01-01', end='2023-12-31', freq='D'),
'Open': np.random.normal(100, 2, 365).cumsum(),
'High': None,
'Low': None,
'Close': None
})
df_stocks['High'] = df_stocks['Open'] + np.random.uniform(0, 5, 365)
df_stocks['Low'] = df_stocks['Open'] - np.random.uniform(0, 5, 365)
df_stocks['Close'] = df_stocks['Open'] + np.random.normal(0, 2, 365)
fig_candlestick = go.Figure(data=[go.Candlestick(
x=df_stocks['Date'],
open=df_stocks['Open'],
high=df_stocks['High'],
low=df_stocks['Low'],
close=df_stocks['Close']
)])
fig_candlestick.update_layout(
title='Stock Price Movement',
yaxis_title='Stock Price',
xaxis_title='Date',
xaxis_rangeslider_visible=True
)
st.plotly_chart(fig_candlestick)
# 5. Polar Plot
st.header("5. Polar Plot")
theta = np.linspace(0, 2*np.pi, 100)
r = 1 + np.sin(4*theta)
fig_polar = go.Figure(go.Scatterpolar(
r=r,
theta=theta,
mode='lines',
line_color='purple',
fill='toself'
))
fig_polar.update_layout(
title="Mathematical Rose Pattern",
showlegend=False
)
st.plotly_chart(fig_polar)
# 6. Statistical Distribution Plot
st.header("6. Statistical Distribution Plot")
dist_data = np.random.normal(0, 1, 1000)
fig_dist = go.Figure()
fig_dist.add_trace(go.Histogram(
x=dist_data,
histnorm='probability density',
name='Histogram'
))
fig_dist.add_trace(go.Scatter(
x=np.linspace(-4, 4, 100),
y=1/(np.sqrt(2*np.pi)) * np.exp(-np.linspace(-4, 4, 100)**2/2),
mode='lines',
name='Normal Distribution PDF'
))
fig_dist.update_layout(
title='Normal Distribution with Theoretical PDF',
xaxis_title='Value',
yaxis_title='Density'
)
st.plotly_chart(fig_dist)
# 7. 3D Scatter Plot with Categories
st.header("7. 3D Scatter Plot with Categories")
n_points = 1000
df_3d = pd.DataFrame({
'x': np.random.normal(0, 1, n_points),
'y': np.random.normal(0, 1, n_points),
'z': np.random.normal(0, 1, n_points),
'category': np.random.choice(['A', 'B', 'C'], size=n_points),
'size': np.random.uniform(5, 20, n_points)
})
fig_3d = px.scatter_3d(
df_3d,
x='x',
y='y',
z='z',
color='category',
size='size',
title='3D Scatter Plot with Categories'
)
st.plotly_chart(fig_3d)
# 8. Heatmap with Annotations
st.header("8. Heatmap with Annotations")
matrix = np.random.randn(10, 10)
fig_heatmap = px.imshow(
matrix,
labels=dict(x="X Axis", y="Y Axis", color="Value"),
title="Correlation Heatmap"
)
fig_heatmap.update_traces(text=np.round(matrix, 2), texttemplate="%{text}")
st.plotly_chart(fig_heatmap)
Hi! I can help you with any questions about Streamlit and Python. What would you like to know?