awacke1/VizLib-Matplotlib
1
1import streamlit as st2import pandas as pd3import numpy as np4import matplotlib.pyplot as plt5from mpl_toolkits.mplot3d import Axes3D6 7# Sidebar8st.sidebar.header("Select Visualization")9plot_type = st.sidebar.selectbox("Choose a plot type", ("Heatmap", "3D Heatmap", "Contour", "Quiver", "Contourf", "Streamplot", "Hexbin", "Eventplot", "Tricontour", "Triplot"))10 11# Load Data12# data = pd.read_csv("healthcare_treatments.csv")13 14# Define Functions for each plot type15def heatmap():16 fig, ax = plt.subplots()17 ax.set_title("Top Health Care Treatments")18 heatmap_data = np.random.rand(10, 10)19 im = ax.imshow(heatmap_data, cmap="YlOrRd")20 plt.colorbar(im, ax=ax)21 st.pyplot(fig)22 23def heatmap_3d():24 fig = plt.figure()25 ax = fig.add_subplot(111, projection='3d')26 ax.set_title("Top Health Care Treatments")27 x, y = np.meshgrid(range(10), range(10))28 z = np.random.rand(10, 10)29 ax.plot_surface(x, y, z, cmap="YlOrRd")30 st.pyplot(fig)31 32def contour():33 fig, ax = plt.subplots()34 ax.set_title("Top Health Care Treatments")35 x = np.linspace(-3, 3, 100)36 y = np.linspace(-3, 3, 100)37 X, Y = np.meshgrid(x, y)38 Z = np.sin(np.sqrt(X**2 + Y**2))39 ax.contour(X, Y, Z, cmap="YlOrRd")40 st.pyplot(fig)41 42def quiver():43 fig, ax = plt.subplots()44 ax.set_title("Top Health Care Treatments")45 x = np.arange(-2, 2, 0.2)46 y = np.arange(-2, 2, 0.2)47 X, Y = np.meshgrid(x, y)48 U = np.cos(X)49 V = np.sin(Y)50 ax.quiver(X, Y, U, V)51 st.pyplot(fig)52 53def contourf():54 fig, ax = plt.subplots()55 ax.set_title("Top Health Care Treatments")56 x = np.linspace(-3, 3, 100)57 y = np.linspace(-3, 3, 100)58 X, Y = np.meshgrid(x, y)59 Z = np.sin(np.sqrt(X**2 + Y**2))60 ax.contourf(X, Y, Z, cmap="YlOrRd")61 st.pyplot(fig)62 63def streamplot():64 fig, ax = plt.subplots()65 ax.set_title("Top Health Care Treatments")66 x, y = np.linspace(-3, 3, 100), np.linspace(-3, 3, 100)67 X, Y = np.meshgrid(x, y)68 U = -1 - X**2 + Y69 V = 1 + X - Y**270 ax.streamplot(X, Y, U, V, density=[0.5, 1], cmap="YlOrRd")71 st.pyplot(fig)72 73def hexbin():74 fig, ax = plt.subplots()75 ax.set_title("Top Health Care Treatments")76 x = np.random.normal(0, 1, 1000)77 y = np.random.normal(0, 1, 1000)78 ax.hexbin(x, y, gridsize=20, cmap="YlOrRd")79 st.pyplot(fig)80 81def eventplot():82 fig, ax = plt.subplots()83 ax.set_title("Top Health Care Treatments")84 data = np.random.rand(10, 10) > 0.585 ax.eventplot(np.where(data))86 st.pyplot(fig)87 88def tricontour():89 fig, ax = plt.subplots()90 ax.set_title("Top Health Care Treatments")91 x = np.random.rand(10)92 y = np.random.rand(10)93 z = np.random.rand(10)94 ax.tricontour(x, y, z, cmap="YlOrRd")95 st.pyplot(fig)96 97def triplot():98 fig, ax = plt.subplots()99 ax.set_title("Top Health Care Treatments")100 x = np.random.rand(10)101 y = np.random.rand(10)102 tri = np.random.randint(0, 10, (10, 3))103 ax.triplot(x, y, tri)104 st.pyplot(fig)105 106def voxel():107 fig = plt.figure()108 ax = fig.gca(projection='3d')109 ax.set_title("Top Health Care Treatments")110 x, y, z = np.indices((8, 8, 8))111 voxels = (x < 4) & (y < 4) & (z < 4)112 ax.voxels(voxels, facecolors='YlOrRd', edgecolor='k')113 st.pyplot(fig)114 115st.title("Top Health Care Treatments Visualizations")116 117if plot_type == "Heatmap":118 heatmap()119elif plot_type == "3D Heatmap":120 heatmap_3d()121elif plot_type == "Contour":122 contour()123elif plot_type == "Quiver":124 quiver()125elif plot_type == "Contourf":126 contourf()127elif plot_type == "Streamplot":128 streamplot()129elif plot_type == "Hexbin":130 hexbin()131elif plot_type == "Eventplot":132 eventplot()133elif plot_type == "Tricontour":134 tricontour()135elif plot_type == "Triplot":136 triplot()137 138 139st.markdown("""140# ๐ Discover the Power of Matplotlib: A Tutorial to Create Stunning Visualizations in Python ๐141 142Python 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.143 144## ๐จ Versatile Library for Creating Charts and Graphs145 146Matplotlib 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.147 148## ๐ Interactive Visualizations with Streamlit149 150In 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.151 152## ๐ป Lots of Code Examples and Images153 154With 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.155 156## ๐ For Everyone, from Beginners to Experts157 158Whether 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.159 160""")