Spaces:
Runtime error
Runtime error
import streamlit as st | |
import pandas as pd | |
import numpy as np | |
import matplotlib.pyplot as plt | |
from mpl_toolkits.mplot3d import Axes3D | |
# Sidebar | |
st.sidebar.header("Select Visualization") | |
plot_type = st.sidebar.selectbox("Choose a plot type", ("Heatmap", "3D Heatmap", "Contour", "Quiver", "Contourf", "Streamplot", "Hexbin", "Eventplot", "Tricontour", "Triplot")) | |
# Load Data | |
# data = pd.read_csv("healthcare_treatments.csv") | |
# Define Functions for each plot type | |
def heatmap(): | |
fig, ax = plt.subplots() | |
ax.set_title("Top Health Care Treatments") | |
heatmap_data = np.random.rand(10, 10) | |
im = ax.imshow(heatmap_data, cmap="YlOrRd") | |
plt.colorbar(im, ax=ax) | |
st.pyplot(fig) | |
def heatmap_3d(): | |
fig = plt.figure() | |
ax = fig.add_subplot(111, projection='3d') | |
ax.set_title("Top Health Care Treatments") | |
x, y = np.meshgrid(range(10), range(10)) | |
z = np.random.rand(10, 10) | |
ax.plot_surface(x, y, z, cmap="YlOrRd") | |
st.pyplot(fig) | |
def contour(): | |
fig, ax = plt.subplots() | |
ax.set_title("Top Health Care Treatments") | |
x = np.linspace(-3, 3, 100) | |
y = np.linspace(-3, 3, 100) | |
X, Y = np.meshgrid(x, y) | |
Z = np.sin(np.sqrt(X**2 + Y**2)) | |
ax.contour(X, Y, Z, cmap="YlOrRd") | |
st.pyplot(fig) | |
def quiver(): | |
fig, ax = plt.subplots() | |
ax.set_title("Top Health Care Treatments") | |
x = np.arange(-2, 2, 0.2) | |
y = np.arange(-2, 2, 0.2) | |
X, Y = np.meshgrid(x, y) | |
U = np.cos(X) | |
V = np.sin(Y) | |
ax.quiver(X, Y, U, V) | |
st.pyplot(fig) | |
def contourf(): | |
fig, ax = plt.subplots() | |
ax.set_title("Top Health Care Treatments") | |
x = np.linspace(-3, 3, 100) | |
y = np.linspace(-3, 3, 100) | |
X, Y = np.meshgrid(x, y) | |
Z = np.sin(np.sqrt(X**2 + Y**2)) | |
ax.contourf(X, Y, Z, cmap="YlOrRd") | |
st.pyplot(fig) | |
def streamplot(): | |
fig, ax = plt.subplots() | |
ax.set_title("Top Health Care Treatments") | |
x, y = np.linspace(-3, 3, 100), np.linspace(-3, 3, 100) | |
X, Y = np.meshgrid(x, y) | |
U = -1 - X**2 + Y | |
V = 1 + X - Y**2 | |
ax.streamplot(X, Y, U, V, density=[0.5, 1], cmap="YlOrRd") | |
st.pyplot(fig) | |
def hexbin(): | |
fig, ax = plt.subplots() | |
ax.set_title("Top Health Care Treatments") | |
x = np.random.normal(0, 1, 1000) | |
y = np.random.normal(0, 1, 1000) | |
ax.hexbin(x, y, gridsize=20, cmap="YlOrRd") | |
st.pyplot(fig) | |
def eventplot(): | |
fig, ax = plt.subplots() | |
ax.set_title("Top Health Care Treatments") | |
data = np.random.rand(10, 10) > 0.5 | |
ax.eventplot(np.where(data)) | |
st.pyplot(fig) | |
def tricontour(): | |
fig, ax = plt.subplots() | |
ax.set_title("Top Health Care Treatments") | |
x = np.random.rand(10) | |
y = np.random.rand(10) | |
z = np.random.rand(10) | |
ax.tricontour(x, y, z, cmap="YlOrRd") | |
st.pyplot(fig) | |
def triplot(): | |
fig, ax = plt.subplots() | |
ax.set_title("Top Health Care Treatments") | |
x = np.random.rand(10) | |
y = np.random.rand(10) | |
tri = np.random.randint(0, 10, (10, 3)) | |
ax.triplot(x, y, tri) | |
st.pyplot(fig) | |
def voxel(): | |
fig = plt.figure() | |
ax = fig.gca(projection='3d') | |
ax.set_title("Top Health Care Treatments") | |
x, y, z = np.indices((8, 8, 8)) | |
voxels = (x < 4) & (y < 4) & (z < 4) | |
ax.voxels(voxels, facecolors='YlOrRd', edgecolor='k') | |
st.pyplot(fig) | |
st.title("Top Health Care Treatments Visualizations") | |
if plot_type == "Heatmap": | |
heatmap() | |
elif plot_type == "3D Heatmap": | |
heatmap_3d() | |
elif plot_type == "Contour": | |
contour() | |
elif plot_type == "Quiver": | |
quiver() | |
elif plot_type == "Contourf": | |
contourf() | |
elif plot_type == "Streamplot": | |
streamplot() | |
elif plot_type == "Hexbin": | |
hexbin() | |
elif plot_type == "Eventplot": | |
eventplot() | |
elif plot_type == "Tricontour": | |
tricontour() | |
elif plot_type == "Triplot": | |
triplot() |