awacke1's picture
Update app.py
28e4b29
raw
history blame
5.43 kB
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()
st.markdown("""
# ๐Ÿ“ˆ Discover the Power of Matplotlib: A Tutorial to Create Stunning Visualizations in Python ๐Ÿ
Python enthusiasts and data scientists, rejoice! Our new Matplotlib tutorial will teach you how to create professional-quality visualizations to take your data analysis to the next level.
## ๐ŸŽจ Versatile Library for Creating Charts and Graphs
Matplotlib is a powerful and versatile library that enables you to create a wide range of charts and graphs with ease. From heatmaps to 3D visualizations, our tutorial covers 10 different types of plots, allowing you to choose the perfect one for your data.
## ๐Ÿš€ Interactive Visualizations with Streamlit
In this tutorial, you'll learn how to use Matplotlib with Streamlit to interactively display your visualizations, making it easy to share your work with others. Our step-by-step guide is designed to be accessible to beginners, while also providing advanced techniques for more experienced users.
## ๐Ÿ’ป Lots of Code Examples and Images
With lots of code examples and images, our tutorial will guide you through creating heatmaps, contour plots, quiver plots, and many more. You'll also learn how to customize your visualizations with color maps and labels, and how to create 3D plots that showcase your data in a whole new dimension.
## ๐ŸŽ“ For Everyone, from Beginners to Experts
Whether you're a data analyst, a data scientist, or simply looking to add data visualization skills to your repertoire, our Matplotlib tutorial has something for everyone. So don't wait any longer to unleash the power of Matplotlib and create stunning visualizations that bring your data to life.
""")