avatarTrainDataHub

Free AI web copilot to create summaries, insights and extended knowledge, download it at here

2105

Abstract

="hljs-attribute">data</span>=df, <span class="hljs-attribute">x</span>=<span class="hljs-string">"DiastolicBP"</span>, <span class="hljs-attribute">kde</span>=<span class="hljs-literal">True</span>, <span class="hljs-attribute">color</span>=<span class="hljs-string">"gold"</span>, <span class="hljs-attribute">ax</span>=axs[1, 0]) sns.histplot(<span class="hljs-attribute">data</span>=df, <span class="hljs-attribute">x</span>=<span class="hljs-string">"BS"</span>, <span class="hljs-attribute">kde</span>=<span class="hljs-literal">True</span>, <span class="hljs-attribute">color</span>=<span class="hljs-string">"teal"</span>, <span class="hljs-attribute">ax</span>=axs[1, 1]) sns.histplot(<span class="hljs-attribute">data</span>=df, <span class="hljs-attribute">x</span>=<span class="hljs-string">"BodyTemp"</span>, <span class="hljs-attribute">kde</span>=<span class="hljs-literal">True</span>, <span class="hljs-attribute">color</span>=<span class="hljs-string">"teal"</span>, <span class="hljs-attribute">ax</span>=axs[2, 0]) sns.histplot(<span class="hljs-attribute">data</span>=df, <span class="hljs-attribute">x</span>=<span class="hljs-string">"HeartRate"</span>, <span class="hljs-attribute">kde</span>=<span class="hljs-literal">True</span>, <span class="hljs-attribute">color</span>=<span class="hljs-string">"blue"</span>, <span class="hljs-attribute">ax</span>=axs[2, 1]) sns.histplot(<span class="hljs-attribute">data</span>=df, <span class="hljs-attribute">x</span>=<span class="hljs-string">"RiskLevel"</span>, <span class="hljs-attribute">kde</span>=<span class="hljs-literal">True</span>, <span class="hljs-attribute">color</span>=<span class="hljs-string">"purple"</span>, <span class="hljs-attribute">ax</span>=axs[3,0])</pre></div><div id="dcaa"><pre>fig.tight_layout<span class="hljs-comment">()</span></pre></div><p id="9600">Then we will get nice multiple histograms like this.</p><p id="6bf6">For the code above, sns.set(style=”whitegrid”) was used. There are additional options such as dark, white, darkgrid, ticks in addition to the whitegrid.</p><figure id="da0d"><img src

Options

="https://cdn-images-1.readmedium.com/v2/resize:fit:800/1*VWv02IoI7uvpggGBQpf1pQ.png"><figcaption></figcaption></figure><p id="c3c2">Using Dark Style</p><figure id="a848"><img src="https://cdn-images-1.readmedium.com/v2/resize:fit:800/1*ks6GZlGBAsDg_0TtEbNHfQ.png"><figcaption></figcaption></figure><p id="19b3"><b>Multiple Histograms using Matplotlib Histgram Method</b></p><p id="9d0b">Python Code</p><div id="faf9"><pre>%matplotlib <span class="hljs-keyword">inline</span> <span class="hljs-keyword">import</span> matplotlib.pyplot <span class="hljs-keyword">as</span> plt</pre></div><div id="c2d2"><pre>fig = plt<span class="hljs-selector-class">.figure</span>(figsize = (<span class="hljs-number">8</span>,<span class="hljs-number">10</span>)) ax = fig<span class="hljs-selector-class">.gca</span>() df<span class="hljs-selector-class">.hist</span>(ax=ax, <span class="hljs-attribute">color</span> = <span class="hljs-string">"skyblue"</span>) plt<span class="hljs-selector-class">.show</span>()</pre></div><figure id="0745"><img src="https://cdn-images-1.readmedium.com/v2/resize:fit:800/1*jnrDwiRRSRGQmDjXn3y1XQ.png"><figcaption></figcaption></figure><p id="f75b">We can decorate the above figure a bit by adding edge color.</p><p id="084e">So the code will look like this.</p><div id="56e4"><pre>fig = plt<span class="hljs-selector-class">.figure</span>(figsize = (<span class="hljs-number">8</span>,<span class="hljs-number">10</span>)) ax = fig<span class="hljs-selector-class">.gca</span>() df<span class="hljs-selector-class">.hist</span>(ax=ax, <span class="hljs-attribute">color</span> = <span class="hljs-string">"skyblue"</span>, edgecolor = <span class="hljs-string">"gold"</span>) plt<span class="hljs-selector-class">.show</span>()</pre></div><p id="3c58">And here’s the final figure!</p><figure id="51d4"><img src="https://cdn-images-1.readmedium.com/v2/resize:fit:800/1*0PCX4F20IspIsIN60TJICg.png"><figcaption></figcaption></figure><p id="1d1a">Enjoy Seaborn’s and Matplotlib’s Histograms! Please feel free to follow me and drop a line if you have any suggestions!</p></article></body>

How To Construct Cool Multiple Histogram Plots Using Seaborn and Matplotlib in Python

Histograms are cool plots that show the distributions of numeric variables of the dataset. Visualization of the dataset with histograms are essential in EDA process for data scientists since it reveals whether the dataset is normal distribution, positively, negatively skewed,or symmetrical, and the presence of the outliers.

Here are the efficient and quick easy ways to construct all the numerical variables of the dataset using Seaborn and Matplotlib libraries.

Multiple Histograms using Seaborn Histgram Method

Python Code

import seaborn as sns
sns.set(style="whitegrid")  
fig,axs = plt.subplots(3,2, figsize = (8,10))
sns.histplot(data=df, x="Age", kde=True, color="skyblue", ax=axs[0, 0])
sns.histplot(data=df, x="SystolicBP", kde=True, color="olive", ax=axs[0, 1])
sns.histplot(data=df, x="DiastolicBP", kde=True, color="gold", ax=axs[1, 0])
sns.histplot(data=df, x="BS", kde=True, color="teal", ax=axs[1, 1])
sns.histplot(data=df, x="BodyTemp", kde=True, color="teal", ax=axs[2, 0])
sns.histplot(data=df, x="HeartRate", kde=True, color="blue", ax=axs[2, 1])
sns.histplot(data=df, x="RiskLevel", kde=True, color="purple", ax=axs[3,0])
fig.tight_layout()

Then we will get nice multiple histograms like this.

For the code above, sns.set(style=”whitegrid”) was used. There are additional options such as dark, white, darkgrid, ticks in addition to the whitegrid.

Using Dark Style

Multiple Histograms using Matplotlib Histgram Method

Python Code

%matplotlib inline
import matplotlib.pyplot as plt
fig = plt.figure(figsize = (8,10))
ax = fig.gca()
df.hist(ax=ax, color = "skyblue")
plt.show()

We can decorate the above figure a bit by adding edge color.

So the code will look like this.

fig = plt.figure(figsize = (8,10))
ax = fig.gca()
df.hist(ax=ax, color = "skyblue", edgecolor = "gold")
plt.show()

And here’s the final figure!

Enjoy Seaborn’s and Matplotlib’s Histograms! Please feel free to follow me and drop a line if you have any suggestions!

Histograms
Multiple Histograms
Python Matplotlib
Seaborn Tutorial
Eda
Recommended from ReadMedium