|
|
import streamlit as st |
|
|
import pandas as pd |
|
|
import numpy as np |
|
|
import plotly.graph_objs as go |
|
|
import plotly.figure_factory as ff |
|
|
|
|
|
def main(): |
|
|
st.title("Bar Chart and 3D Graph Example") |
|
|
|
|
|
|
|
|
bar_data = pd.DataFrame({ |
|
|
'Category': ['A', 'B', 'C', 'D'], |
|
|
'Values': [10, 20, 15, 25] |
|
|
}) |
|
|
|
|
|
|
|
|
st.write("Sample Data for Bar Chart:") |
|
|
st.write(bar_data) |
|
|
|
|
|
|
|
|
st.write("Bar Chart:") |
|
|
fig_bar = go.Figure(data=[go.Bar(x=bar_data['Category'], y=bar_data['Values'])]) |
|
|
st.plotly_chart(fig_bar) |
|
|
|
|
|
|
|
|
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)) |
|
|
|
|
|
|
|
|
surface_data = pd.DataFrame({'X': X.flatten(), 'Y': Y.flatten(), 'Z': Z.flatten()}) |
|
|
|
|
|
|
|
|
st.write("Sample Data for 3D Surface Plot:") |
|
|
st.write(surface_data.head()) |
|
|
|
|
|
|
|
|
st.write("3D Surface Plot:") |
|
|
fig_surface = go.Figure(data=[go.Surface(z=surface_data['Z'].values.reshape(100, 100), |
|
|
x=surface_data['X'].values.reshape(100, 100), |
|
|
y=surface_data['Y'].values.reshape(100, 100))]) |
|
|
st.plotly_chart(fig_surface) |
|
|
|
|
|
|
|
|
confusion_matrix_data = np.array([[30, 10], [5, 55]]) |
|
|
|
|
|
|
|
|
cm_df = pd.DataFrame(confusion_matrix_data, columns=['Predicted Negative', 'Predicted Positive'], index=['Actual Negative', 'Actual Positive']) |
|
|
|
|
|
|
|
|
st.write("Confusion Matrix Data:") |
|
|
st.write(cm_df) |
|
|
|
|
|
|
|
|
st.write("Confusion Matrix:") |
|
|
fig_cm = ff.create_annotated_heatmap(z=confusion_matrix_data, x=['Predicted Negative', 'Predicted Positive'], y=['Actual Negative', 'Actual Positive'], colorscale='Viridis') |
|
|
fig_cm.update_layout(title="Confusion Matrix", xaxis_title="Predicted Label", yaxis_title="Actual Label") |
|
|
st.plotly_chart(fig_cm) |
|
|
|
|
|
|
|
|
np.random.seed(0) |
|
|
data = np.random.rand(10, 10) |
|
|
|
|
|
|
|
|
heatmap_data = pd.DataFrame(data) |
|
|
|
|
|
|
|
|
st.write("Sample Data for Heatmap:") |
|
|
st.write(heatmap_data.head()) |
|
|
|
|
|
|
|
|
st.write("Heatmap:") |
|
|
fig_heatmap = go.Figure(data=go.Heatmap(z=data)) |
|
|
st.plotly_chart(fig_heatmap) |
|
|
|
|
|
|
|
|
np.random.seed(0) |
|
|
data = np.random.randn(1000) |
|
|
|
|
|
|
|
|
hist_data = pd.DataFrame({'Values': data}) |
|
|
|
|
|
|
|
|
st.write("Sample Data for Histogram:") |
|
|
st.write(hist_data.head()) |
|
|
|
|
|
|
|
|
st.write("Histogram:") |
|
|
fig_hist = go.Figure(data=[go.Histogram(x=hist_data['Values'])]) |
|
|
st.plotly_chart(fig_hist) |
|
|
|
|
|
|
|
|
np.random.seed(0) |
|
|
x = np.random.randn(100) |
|
|
y = np.random.randn(100) |
|
|
|
|
|
|
|
|
scatter_data = pd.DataFrame({'X': x, 'Y': y}) |
|
|
|
|
|
|
|
|
st.write("Sample Data for Scatter Plot:") |
|
|
st.write(scatter_data.head()) |
|
|
|
|
|
|
|
|
st.write("Scatter Plot:") |
|
|
fig_scatter = go.Figure(data=[go.Scatter(x=scatter_data['X'], y=scatter_data['Y'], mode='markers')]) |
|
|
st.plotly_chart(fig_scatter) |
|
|
|
|
|
if __name__ == "__main__": |
|
|
main() |
|
|
|