Commit f70deab1 authored by Mo Shahdloo's avatar Mo Shahdloo Committed by Paul McCarthy
Browse files

revised for the comments raised by Paul

parent 469d7b31
......@@ -23,11 +23,11 @@
``` python
import seaborn as sns
import pandas as pd
import matplotlib.pyplot as plt
import numpy as np
sns.set_theme()
sns.set()
```
%% Cell type:markdown id:champion-answer tags:
## Plotting relative distributions
......@@ -58,11 +58,11 @@
penguins.plot(kind='scatter', x='bill_length_mm', y='bill_depth_mm')
```
%% Cell type:markdown id:significant-behavior tags:
As noted in the beginning, `seaborn` is built on top of `pandas` and `matplotlib`, so everything that is acheivable via `seaborn` is achievable using a -- not so straightforward -- combination of the other two. But the magic of `seaborn` is that it makes the job of producing various publication-quality figures magnitudes of orders easier.
As noted in the beginning, `seaborn` is built on top of `pandas` and `matplotlib`, so everything that is acheivable via `seaborn` is achievable using a -- not so straightforward -- combination of the other two. But the magic of `seaborn` is that it makes the job of producing various publication-quality figures orders of magnitudes easier.
Let's start by plotting the same scatterplot, but this time via `seaborn`. To do this, we have to pass the names of columns of interest to the `x` and `y` parameters corresponding to the horizontal and vertical axes.
%% Cell type:code id:placed-egyptian tags:
......@@ -137,11 +137,11 @@
plt.show()
```
%% Cell type:markdown id:fuzzy-welsh tags:
paranthesis closed.
parenthesis closed.
---
%% Cell type:markdown id:architectural-corruption tags:
......@@ -363,21 +363,22 @@
%% Cell type:code id:realistic-batman tags:
``` python
# define the JointGrid, and the data corresponding to each axis
g = sns.JointGrid(data=planets, x="distance", y="orbital_period", marginal_ticks=True)
g = sns.JointGrid(data=planets, x="distance", y="orbital_period")
# the axes should be log-scaled!
g.ax_joint.set(yscale="log", xscale="log")
# plot the joint scatter plot in the joint axis
# Heavier planets are marked with larger dots, and `sizes` controls the range of marker sizes
g.plot_joint(sns.scatterplot, size=planets.mass, sizes=(10, 200))
# plot the joint histograms, overlayed with kernel density estimates
g.plot_marginals(sns.histplot, kde=True)
g.plot_marginals(sns.distplot, kde=False,
bins=np.logspace(np.log10(1),np.log10(5000), 30))
```
%% Cell type:markdown id:restricted-damages tags:
---
......@@ -385,24 +386,37 @@
## Pairwise relationships
<a id='pair'></a>
`seaborn` also provides a convenient tool to have an overview of the relationships among each pair of the columns in a large table using `pairplot`. This could hint to potential dependencies among variables.
Lets see the overview of the pairwise relationships in the 🐧 dataset.
Lets see the overview of the pairwise relationships in a dataset that contains the data on iris flowers 🌸.
%% Cell type:code id:fancy-trial tags:
``` python
iris = sns.load_dataset('iris')
```
%% Cell type:code id:medium-department tags:
``` python
iris
```
%% Cell type:code id:boolean-mineral tags:
``` python
sns.pairplot(penguins)
sns.pairplot(iris)
```
%% Cell type:markdown id:pressed-clone tags:
By default, scatterplots are used to show the distribution of each pair, and histograms of marginal distributions are shown on the diagonal. Note, however, that the upper-diagonal, lower-diagonal, and diagonal plots can be modified independently. For instance, we can plot the linear regression lines in the upper-diagonal plots using `regplot`, marginal histograms on the diagonals using `hist`, and kernel density estimates in the lowe-diagonal plots using `kdeplot`.
By default, scatterplots are used to show the distribution of each pair, and histograms of marginal distributions are shown on the diagonal. Note, however, that the upper-diagonal, lower-diagonal, and diagonal plots can be modified independently. For instance, we can plot the linear regression lines in the upper-diagonal plots using `regplot`, marginal histograms on the diagonals using `kdeplot`, and kernel density estimates in the lower-diagonal plots also using `kdeplot`.
%% Cell type:code id:rocky-education tags:
``` python
g = sns.pairplot(penguins, diag_kind="hist")
g.map_lower(sns.kdeplot, levels=4, color="green")
g.map_upper(sns.regplot, line_kws={"color": "red"})
g = sns.PairGrid(iris, diag_sharey=False)
g.map_upper(sns.regplot, line_kws={'color':'green'})
g.map_lower(sns.kdeplot)
g.map_diag(sns.kdeplot, lw=3)
```
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment