<jupyter_start><jupyter_text>Plotting graphs with Seaborn<jupyter_code>import numpy as np
import pandas as pd

import matplotlib.pyplot as plt
import seaborn as sns
iris = sns.load_dataset('iris')
iris.shape
iris.head()
iris['species'].unique()<jupyter_output><empty_output><jupyter_text>Univariate Analysis  Histogram  Definition Histogram indicates how numerical data are distributed. or it is a **graphical representation of data points grouped into ranges** that the user specifies. or Histograms illustrate the frequency distribution of data sets. Key Pointers   - Histograms show data in a bar graph-like manner by grouping outcomes along a vertical axis.  - The y-axis of a histogram represents occurrences, either by number or by percentage or in simple words the height of each bar represents either a number count or a percentage.  - MACD (Moving Average Convergence Divergence) histograms are used in technical analysis to indicate changes in momentum in the market.    Difference between histograms and bar charts Often, histograms are confused with bar charts.Generally, a histogram is used to plot continuous data, in which each bin represents a range of values, while a bar chart shows categorical dataMore techincally,Histograms depict the frequency distribution of variables in a data set. A bar graph, by contrast, represents a graphical comparison of discrete or categorical variables. A Histogram's FunctionIn statistics, histograms are used to indicate the frequencies of particular types of variables occurring within a defined range. As an example, a census that focuses on the demography of a country may show a histogram showing the number of people aged 0 - 10, 11 - 20, 21 - 30, 31 - 40, 41 - 50, etc.A histogram can be customized in several ways by the analyst. As an alternative to frequency, one could use percent of total or density as labels.Another factor to consider would be bucket size. In the above example, there are 5 buckets with an interval of ten. You could change this, for example, to 10 buckets with a 5-minute interval instead.A histogram gives a rough idea of the underlying distribution of data, and is often used for density estimation: estimating the probability density function of underlying variables.<jupyter_code>iris['petal_length']
sns.histplot(data=iris,x = 'petal_length',bins = 30)
sns.histplot(data=iris,x = 'petal_length',bins = 30,hue='species')<jupyter_output><empty_output><jupyter_text>KDE - Kernel Density Estimationcontiuous probability density function (PDF)<jupyter_code>sns.kdeplot(data = iris, x='petal_length')
sns.kdeplot(data = iris, x='petal_length',hue='species')
plt.show()<jupyter_output><empty_output><jupyter_text>Distribution plot<jupyter_code>sns.displot(data=iris,x='sepal_length',bins=40,hue='species')<jupyter_output><empty_output><jupyter_text>Bivariante Analysis  Scatter plot - using seaborn<jupyter_code>sns.scatterplot(data=iris,x='petal_length',y = 'petal_width',hue='species')
#plt.xlim(-5,10)
plt.show()<jupyter_output><empty_output><jupyter_text>scatter plot using matplotlib<jupyter_code>setosa = iris[iris['species'] == 'setosa']
versicolor = iris[iris['species'] == 'versicolor']
virginica = iris[iris['species'] == 'virginica']
plt.scatter(x=setosa['petal_length'],y=setosa['petal_width'], c = 'blue')
plt.scatter(x=versicolor['petal_length'],y=versicolor['petal_width'], c = 'orange')
plt.scatter(x=virginica['petal_length'],y=virginica['petal_width'], c = 'green')<jupyter_output><empty_output><jupyter_text>Joint plot (Default it joins displot and scatterplot)<jupyter_code>sns.jointplot(data=iris,x='petal_length',y='petal_width',hue='species')
plt.show
# ['scatter', 'hist', 'hex', 'kde', 'reg', 'resid']
sns.jointplot(data=iris,x='petal_length',y='petal_width',kind='reg')
plt.show
sns.jointplot(data=iris,x='petal_length',y='petal_width',hue='species',kind='kde')
plt.show
sns.jointplot(data=iris,x='sepal_length',y='sepal_width',kind='hex')
plt.show<jupyter_output><empty_output><jupyter_text>Multivariate Analysis<jupyter_code>iris.head()
sns.pairplot(data = iris, hue='species')<jupyter_output><empty_output><jupyter_text>Categorial variables  Univariate Analysis<jupyter_code>iris.head()
sns.countplot(data=iris,x = 'species')<jupyter_output><empty_output><jupyter_text>Box plot<jupyter_code>sns.boxplot(data=iris, y = 'petal_length')<jupyter_output><empty_output><jupyter_text>Boxplot for Multi-variant Analysis<jupyter_code>sns.boxplot(data=iris,x = 'species', y = 'sepal_length')<jupyter_output><empty_output><jupyter_text>violinplot shows distribution and outliers.<jupyter_code>sns.violinplot(data=iris,x = 'species', y = 'sepal_length')<jupyter_output><empty_output><jupyter_text>Matrix Plots<jupyter_code>corr = iris.corr()
corr
sns.heatmap(corr,annot = True)
car_crashes = sns.load_dataset('car_crashes').corr()
sns.heatmap(car_crashes.corr(),annot = True)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.10950244698205547, 'fraction_numerical': 0.0065252854812398045, 'mean_word_length': 7.901996370235935, 'pattern_counts': {'":': 0, '<': 53, '<?xml version=': 0, '>': 53, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '13', 'dir': 'jupyter-structured-clean-dedup', 'id': '320241', 'license': 'MIT', 'n_tokens_mistral': 1688, 'n_tokens_neox': 1568, 'n_words': 429, 'path': 'Data-Visualization/Seaborn/Plotting graphs with Seaborn.ipynb', 'repo_name': 'Akshat-MS/DataScience-Learning', 'size': '4904'}