Jay's Cookbook
Menu
  • Tags
  • Categories
  • Projects
Computer Science
OS
Network
Data Structure
Algorithm
Language
Code Architecture
Python
Javascript
Typescript
Java
Backend
Backend Theory
TypeORM
Node.js
NestJS
FastAPI
Frontend
HTML/CSS
React
Next.js
Data Engineering
DE Theory
MySQL
MongoDB
Elastic
Redis
Kafka
Spark
Airflow
AI
Basic
Pytorch
NLP
Computer Vision
Data Analytics
Statistics
Pandas
Matplotlib
DevOps
Git
Docker
Kubernetes
AWS
Matplotlib Series [Part8] Histogram Plot
data_analytics
matplotlib

Matplotlib Series [Part8] Histogram Plot

Jay Kim
Jay Kim 20 Jan 2022
Matplotlib Series [Part7] Bar Plot Matplotlib Series [Part9] Pie Plot

Table of Contents

  • 히스토그램 기본
  • 히스토그램 꾸미기
  • 여러 개의 히스토그램
  • 텍스트 넣기

import numpy as np
import matplotlib.pyplot as plt

n_data = 1000
data = np.random.normal(0, 1, (n_data,))

히스토그램 기본

fig, ax = plt.subplots(figsize=(4, 3))

ax.hist(data)

ax.hist(data, bins=20)

히스토그램 꾸미기

ax.hist(data, facecolor='skyblue', edgecolor='darkblue', hatch='/')

여러 개의 히스토그램

fig, ax = plt.subplots(figsize=(4, 3))

ax.hist(data, facecolor='skyblue', edgecolor='darkblue', hatch='/')
ax.hist(data, bins=20, facecolor='coral', edgecolor='red', linewidth=3)

fig, ax = plt.subplots(figsize=(4, 3))

ax.hist(data, bins=10, align='mid', alpha=0.5)
ax.hist(data, bins=20, facecolor='coral', align='left', alpha=0.5)
ax.hist(data, bins=20, facecolor='skyblue', align='right', alpha=0.5)

n_class = 3
n_data = 300

data = np.random.normal(0, 1, (n_data, n_class))

fig, ax = plt.subplots(figsize=(14, 10))
ax.hist(data)

텍스트 넣기

n_data = 1000
data = np.random.normal(0, 1, (n_data,))

fig, ax = plt.subplots(figsize=(6, 4))

freqs, bin_edges, rects = ax.hist(data, edgecolor='darkblue')

for idx, rect in enumerate(rects):
    width = rect.get_width()
    x_pos = rect.get_x()
    y_pos = rect.get_height()
    ax.text(x_pos + width/2, y_pos + 2, int(freqs[idx]), ha='center', fontsize=8)

Matplotlib Series [Part7] Bar Plot Matplotlib Series [Part9] Pie Plot

You may also like

See all matplotlib
21 Jan 2022 Matplotlib Series [Part11] Box and Whisker Plot
data_analytics
matplotlib

Matplotlib Series [Part11] Box and Whisker Plot

21 Jan 2022 Matplotlib Series [Part10] Scatter Plot
data_analytics
matplotlib

Matplotlib Series [Part10] Scatter Plot

20 Jan 2022 Matplotlib Series [Part9] Pie Plot
data_analytics
matplotlib

Matplotlib Series [Part9] Pie Plot

Jay Kim

Jay Kim

Web development, data engineering for human for the Earth. I share posts, free resources and inspiration.

Rest
Lifestyle
Hobby
Hobby
Hobby
Hobby
2025 © Jay's Cookbook. Crafted & Designed by Artem Sheludko.