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 [Part4] Color
data_analytics
matplotlib

Matplotlib Series [Part4] Color

Jay Kim
Jay Kim 20 Jan 2022
Matplotlib Series [Part3] Text Matplotlib Series [Part5] Tick, Grid 그리고 Spine

Table of Contents

  • Named Color
  • Colormap
  • Style

Named Color

Colormap

pastel_cmap = cm.get_cmap('Pastel1') # matplotlib.colors.ListedColormap (불연속)

tab10_cmap = cm.get_cmap('tab10') # matplotlib.colors.ListedColormap (불연속)

ylorbr_cmap = cm.get_cmap('YlOrBr') # matplotlib.colors.LinearSegmentedColormap (연속)
# 불연속한 경우 cmap.colors 를 통해 리스트를 얻을 수 있다
fig, ax = plt.subplots(figsize=(10, 5))
ax.set_ylim([-1, len(tab10_cmap.colors)])
for i in range(len(tab10_cmap.colors)):
    ax.text(0.5, i, "color="+str(tab10_cmap(i)), color=tab10_cmap(i), ha='center')

# 연속할 경우 리스트를 얻을 수 없다
fig, ax = plt.subplots(figsize=(10, 5))
ax.set_ylim([-1, 100])
for i in range(100):
    ax.text(0.5, i, "color="+str(ylorbr_cmap(i)), color=ylorbr_cmap(i), ha='center')

Style

  • 색깔을 테마 정하듯이 자동으로 지정할 수도 있다
# 가능한 스타일
plt.style.available
-------------------------------------
['Solarize_Light2',
 '_classic_test_patch',
 '_mpl-gallery',
 '_mpl-gallery-nogrid',
 'bmh',
 'classic',
 'dark_background',
 'fast',
 'fivethirtyeight',
 'ggplot',
 'grayscale',
 'seaborn-v0_8',
 'seaborn-v0_8-bright',
 'seaborn-v0_8-colorblind',
 'seaborn-v0_8-dark',
 'seaborn-v0_8-dark-palette',
 'seaborn-v0_8-darkgrid',
 'seaborn-v0_8-deep',
 'seaborn-v0_8-muted',
 'seaborn-v0_8-notebook',
 'seaborn-v0_8-paper',
 'seaborn-v0_8-pastel',
 'seaborn-v0_8-poster',
 'seaborn-v0_8-talk',
 'seaborn-v0_8-ticks',
 'seaborn-v0_8-white',
 'seaborn-v0_8-whitegrid',
 'tableau-colorblind10']
plt.style.use('seaborn-pastel')
  • 적용 전

  • 적용 후

Matplotlib Series [Part3] Text Matplotlib Series [Part5] Tick, Grid 그리고 Spine

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.