Team Ai
Apppublic

Nagendra18/Matplotlib-Seaborn

sourceHugging Faceupdated 2y agoView on Hugging Face
0likes
11_catplot- sankey plot- Q-Qplots.py159 linesDownload Raw Back to pages
1import seaborn as sns2import numpy as np3import matplotlib.pyplot as plt4import streamlit as st5from matplotlib.sankey import Sankey6import scipy.stats as stats7import pySankey8from pySankey.sankey import sankey9 10 11 12st.title(":blue[Catplot]")13st.markdown("<hr style='border: none; height: 5px; background-color: purple;'>", unsafe_allow_html=True)14 15st.markdown("""16A **catplot** in Seaborn is a versatile function that creates a multi-plot grid for categorical data. It can visualize various relationships and distributions among categorical and continuous variables.17 18**Types of Analysis:**19- **Univariate:** Analyzing a single categorical variable.20- **Bivariate:** Analyzing the relationship between a categorical variable and a continuous variable.21- **Multivariate:** Analyzing multiple categorical and continuous variables.22""")23plt.title('Box Plot of Sepal Length by Species')24st.write("""25```python26iris = sns.load_dataset('iris')27 28sns.catplot(x='species', y='sepal_length', data=iris, kind='box')29st.pyplot(plt)30```31""")32iris = sns.load_dataset('iris')33 34sns.catplot(x='species', y='sepal_length', data=iris, kind='box')35st.pyplot(plt)36 37 38 39plt.title('Violin Plot of Age by Class')40st.write("""41```python42titanic = sns.load_dataset('titanic')43sns.catplot(x='class', y='age', data=titanic, kind='violin')44st.pyplot(plt)45```46""")47titanic = sns.load_dataset('titanic')48sns.catplot(x='class', y='age', data=titanic, kind='violin')49st.pyplot(plt)50 51 52 53st.title(":blue[Sankey Plot]")54st.markdown("<hr style='border: 2px dashed rainbow;'>", unsafe_allow_html=True)55 56st.markdown("""57A **Sankey plot** is a specialized flow diagram that visualizes the flow and relationships between entities. It is commonly used to show the movement or distribution of resources, such as energy, money, or information.58 59**Types of Analysis:**60- **Bivariate:** Analyzing the relationship between two categorical variables, showing how they contribute to overall flow.61- **Multivariate:** Representing multiple dimensions of relationships or flows.62""")63 64 65plt.title('Sankey Diagram Example')66st.write("""67```python68import pySankey69from pySankey.sankey import sankey70 71f1=np.random.choice(["apple","mango","banannaa","grap","kiwi"],size=(10,))72f2=np.random.choice(["apple","mango","banannaa","grap",],size=(10,))73cost=np.random.randint(10,50,size=(10,))74pd.DataFrame({"fruit_1":f1,"fruit_2":f2,"cost":v1})75sankey(left=f1,right=f2)76 77 78 79 80```81""")82 83 84st.image("https://cdn-uploads.huggingface.co/production/uploads/66be1362737c4ed890949fa1/JUNwr0Irpt_u-CAAmmfU2.png")85st.write("""86```python87import pySankey88from pySankey.sankey import sankey89 90f1=np.random.choice(["apple","mango","banannaa","grap","kiwi"],size=(10,))91f2=np.random.choice(["apple","mango","banannaa","grap",],size=(10,))92cost=np.random.randint(10,50,size=(10,))93pd.DataFrame({"fruit_1":f1,"fruit_2":f2,"cost":v1})94  95sankey(left=f1,right=f2,leftWeight=v1,rightWeight=v1)96```97""")98 99st.image("https://cdn-uploads.huggingface.co/production/uploads/66be1362737c4ed890949fa1/StNAU5eY8UKDGuW0BGAdU.png")100 101 102 103st.title(":blue[Q-Q Plot]")104st.markdown("<hr style='border: none; height: 5px; background-color: pink;'>", unsafe_allow_html=True)105 106st.markdown("""107A **Q-Q plot** (Quantile-Quantile plot) is a graphical tool used to compare the distribution of a dataset against a theoretical distribution (like normal distribution) or another dataset. It helps in assessing if the data follows a specific distribution.108 109**Types of Analysis:**110- **Univariate:** Analyzing the distribution of a single variable.111""")112 113st.title("Q-Q Plot Example")114st.subheader("Histogram of Generated Data")115st.write("""116```python117data = np.random.normal(loc=0, scale=1, size=1000)118 119 120 121plt.figure(figsize=(10, 5))122plt.hist(data, bins=30, alpha=0.7, color='blue', edgecolor='red')123plt.title("Histogram")124plt.xlabel("Value")125plt.ylabel("Frequency")126st.pyplot(plt)127```128""")129data = np.random.normal(loc=0, scale=1, size=1000)130 131 132 133plt.figure(figsize=(10, 5))134plt.hist(data, bins=30, alpha=0.7, color='blue', edgecolor='red')135plt.title("Histogram")136plt.xlabel("Value")137plt.ylabel("Frequency")138st.pyplot(plt)139 140 141 142st.subheader("Q-Q Plot")143st.write("""144```python145plt.figure(figsize=(10, 5))146stats.probplot(data, dist="norm", plot=plt)147plt.title("Q-Q Plot")148plt.xlabel("Theoretical Quantiles")149plt.ylabel("Sample Quantiles")150st.pyplot(plt)151```152""")153plt.figure(figsize=(10, 5))154stats.probplot(data, dist="norm", plot=plt)155plt.title("Q-Q Plot")156plt.xlabel("Theoretical Quantiles")157plt.ylabel("Sample Quantiles")158st.pyplot(plt)159