DEV Community

muradalhasan
muradalhasan

Posted on

Seaborn-High Level Graphical Representation

Data visualization library based on Matplotlib. Provides High Level Graphical Interface.

import seaborn as sns
import matplotlib.pyplot as plt
Enter fullscreen mode Exit fullscreen mode

loading dataset,# draw lineplot,# setting the x limit of the plot# # changing the theme to dark

data = sns.load_dataset("iris")
sns.lineplot(x="sepal_length", y="sepal_width", data=data)
plt.xlim(5)
sns.set_style("dark")
plt.show()
Enter fullscreen mode Exit fullscreen mode

figure() method.

data = sns.load_dataset("iris")
plt.figure(figsize = (4, 4))
sns.lineplot(x="sepal_length", y="sepal_width", data=data)
sns.despine()
plt.show()

Enter fullscreen mode Exit fullscreen mode

set_context() method

Syntax:

set_context(context=None, font_scale=1, rc=None)

data = sns.load_dataset("iris")
sns.lineplot(x="sepal_length", y="sepal_width", data=data)
sns.set_context("poster")
plt.show()
Enter fullscreen mode Exit fullscreen mode

*Subplot Already Discued in Matplotlib

Relational Plots-->Relational plots are used for visualizing the statistical relationship between the data points

Syntax:

seaborn.relplot(x=None, y=None, data=None, **kwargs)

data = sns.load_dataset("iris")
sns.relplot(x='sepal_width', y='species', data=data)

plt.show()
Enter fullscreen mode Exit fullscreen mode

Scatter Plot

Syntax:

seaborn.scatterplot(x=None, y=None, data=None, **kwargs)

data = sns.load_dataset("iris")
sns.scatterplot(x='sepal_length', y='sepal_width', data=data)
plt.show()
Enter fullscreen mode Exit fullscreen mode

Line Plot

Syntax:

seaborn.lineplot(x=None, y=None, data=None, **kwargs)

data = sns.load_dataset("iris")
sns.lineplot(x='sepal_length', y='species', data=data)
plt.show()
Enter fullscreen mode Exit fullscreen mode

Bar Plot

Syntax:

barplot([x, y, hue, data, order, hue_order, …])

data = sns.load_dataset("iris")
sns.barplot(x='species', y='sepal_length', data=data)
plt.show()
Enter fullscreen mode Exit fullscreen mode

Count Plot

Syntax:

countplot([x, y, hue, data, order, …])

data = sns.load_dataset("iris")

sns.countplot(x='species', data=data)
plt.show()
Enter fullscreen mode Exit fullscreen mode

Box Plot

Syntax:

# boxplot([x, y, hue, data, order, hue_order, …])

data = sns.load_dataset("iris")

sns.boxplot(x='species', y='sepal_width', data=data)
plt.show()
Enter fullscreen mode Exit fullscreen mode

Violinplot

Syntax:

violinplot([x, y, hue, data, order, …]

data = sns.load_dataset("iris")

sns.violinplot(x='species', y='sepal_width', data=data)
plt.show()
Enter fullscreen mode Exit fullscreen mode

Stripplot

Syntax:

stripplot([x, y, hue, data, order, …])

data = sns.load_dataset("iris")

sns.stripplot(x='species', y='sepal_width', data=data)
plt.show()
Enter fullscreen mode Exit fullscreen mode

Swarmplot

Syntax:

swarmplot([x, y, hue, data, order, …])

data = sns.load_dataset("iris")

sns.swarmplot(x='species', y='sepal_width', data=data)
plt.show()
Enter fullscreen mode Exit fullscreen mode

Histogram

Syntax:

histplot(data=None, *, x=None, y=None, hue=None, **kwargs)

data = sns.load_dataset("iris")

sns.histplot(x='species', y='sepal_width', data=data)
plt.show()
Enter fullscreen mode Exit fullscreen mode

Distplot

Syntax:

distplot(a[, bins, hist, kde, rug, fit, …])

data = sns.load_dataset("iris")

sns.distplot(data['sepal_width'])
plt.show()

Enter fullscreen mode Exit fullscreen mode

Jointplot

Syntax:

jointplot(x, y[, data, kind, stat_func, …])

data = sns.load_dataset("iris")
sns.jointplot(x='species', y='sepal_width', data=data)
plt.show()
Enter fullscreen mode Exit fullscreen mode

Pairplot

Syntax:

pairplot(data[, hue, hue_order, palette, …])

data = sns.load_dataset("iris")
sns.pairplot(data=data, hue='species')
plt.show()
Enter fullscreen mode Exit fullscreen mode

Rugplot

Syntax:

rugplot(a[, height, axis, ax])

data = sns.load_dataset("iris")
sns.rugplot(data=data)
plt.show()
Enter fullscreen mode Exit fullscreen mode

KDE Plot

Syntax:

seaborn.kdeplot(x=None, *, y=None, vertical=False, palette=None, **kwargs)

data = sns.load_dataset("iris")
sns.kdeplot(x='sepal_length', y='sepal_width', data=data)
plt.show()
Enter fullscreen mode Exit fullscreen mode

Regression Plots

Syntax:

seaborn.lmplot(x, y, data, hue=None, col=None, row=None, **kwargs)

data = sns.load_dataset("tips")
sns.lmplot(x='total_bill', y='tip', data=data)
plt.show()
Enter fullscreen mode Exit fullscreen mode

Regplot

Syntax:

seaborn.regplot( x, y, data=None, x_estimator=None, **kwargs)

data = sns.load_dataset("tips")
sns.regplot(x='total_bill', y='tip', data=data)
plt.show()
Enter fullscreen mode Exit fullscreen mode

Heatmap

Syntax:

seaborn.heatmap(data, *, vmin=None, vmax=None, cmap=None, center=None, annot_kws=None, linewidths=0, linecolor=’white’, cbar=True, **kwargs)

data = sns.load_dataset("tips")
# correlation between the different parameters
tc = data.corr()
sns.heatmap(tc)
plt.show()

Enter fullscreen mode Exit fullscreen mode

Top comments (0)