# 4.5.3 Histogram plot

When dealing with a set of data, often the first thing you’ll want to do is get a sense of how the variables are distributed.

### 1. Basic Histogram

The most convenient way to take a quick look at a univariate distribution in seaborn is  `distplot()`. By default, this will draw a [histogram](https://en.wikipedia.org/wiki/Histogram) and fit a [kernel density estimate](https://en.wikipedia.org/wiki/Kernel_density_estimation) (KDE).

{% content-ref url="/pages/-MBM1SzdkWZfiQCBMSs7" %}
[3.5 Histogram Chart](/crash-visualization/matplotlib/1.4-histogram-plot.md)
{% endcontent-ref %}

```
# Create a simple dataset
d = np.random.multivariate_normal([1, 1], [[6, 2], [2, 2]], size=3000)
df = pd.DataFrame(d, columns=['S1', 'S2'])
```

### 2. Univariate Distribution

```
sns.distplot(df['S1'])
plt.xlabel('x')
```

![](/files/-MBiUvx6w2qYfonDF3_0)

Histograms are likely familiar, and a `hist` function already exists in `matplotlib`. A histogram represents the distribution of data by forming **bins** along with the range of the data and then drawing bars to show the number of observations that fall in each bin. We can try more or fewer bins that may reveal other features in the data.

```
f,axes = plt.subplots(1,2,figsize = (16,6))
sns.distplot(df['S1'], bins=20, kde=False, rug=True,ax = axes[0],color = 'dodgerblue')
axes[0].set_title('Bins: 20')

sns.distplot(df['S1'], bins=200, kde=False, rug=True,ax = axes[1],color = 'dodgerblue')
axes[1].set_title('Bins: 200')
```

![](/files/-MCcR6T9dgKYLXdZygi0)

### 3. Multivariate Distribution

```
sns.distplot(df['S1'],color = 'r',label = 'S1')
sns.distplot(df['S2'],color = 'dodgerblue', label = 'S2')

plt.xlabel('x')
plt.ylabel('Probability')
plt.legend()
```

![](/files/-MBiV-ZhjJW-s5dv9U65)

### 4. Vertical Distribution

It is quite straightforward to make a vertical histogram with seaborn, just add **`vertical=True`** .

```
sns.distplot(df['S1'],color = 'r',label = 'S1',vertical=True)
sns.distplot(df['S2'],color = 'dodgerblue',label = 'S2',vertical=True)

plt.ylabel('x')
plt.xlabel('Probability')
plt.legend()
```

![](/files/-MBiV4-r75EJQwhfvEDA)

### 5. Two Dimensional Distribution

It is also possible to use the kernel density estimation procedure described above to visualize a bivariate distribution.

**Example 1**

```
sns.kdeplot(df, color ='r', shade=True)
```

![](/files/-MBiWrLlx2QC4KlPI3fY)

**Example 2**

```
f, ax = plt.subplots(figsize=(6, 6))
sns.kdeplot(df.S1, df.S2, ax=ax)
sns.rugplot(df.S1, color='r', ax=ax)
sns.rugplot(df.S2, vertical=True, ax=ax)
```

![](/files/-MCcTdpyQiQ5Rrarwht0)


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://vecco-insight.gitbook.io/crash-visualization/seaborn/untitled-3/4.5.3-histogram-plot.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
