Notice
														
												
											
												
												
													Recent Posts
													
											
												
												
													Recent Comments
													
											
												
												
													Link
													
											
									| 일 | 월 | 화 | 수 | 목 | 금 | 토 | 
|---|---|---|---|---|---|---|
| 1 | 2 | 3 | 4 | |||
| 5 | 6 | 7 | 8 | 9 | 10 | 11 | 
| 12 | 13 | 14 | 15 | 16 | 17 | 18 | 
| 19 | 20 | 21 | 22 | 23 | 24 | 25 | 
| 26 | 27 | 28 | 29 | 30 | 31 | 
													Tags
													
											
												
												- IOS
- MS-SQL
- Excel
- tensorflow
- node.js
- port
- 리눅스
- GIT
- Linux
- 맛집
- PyQt
- mssql
- 유니티
- PyQt5
- urllib
- PER
- 다이어트
- swift
- MySQL
- ASP
- pandas
- ubuntu
- Unity
- python
- 함수
- 라즈베리파이
- flutter
- sqlite
- 날짜
- javascript
													Archives
													
											
											
											
											아미(아름다운미소)
Python Named colors in matplotlib 본문
matplotlib에 사용할 수있는 이름이 지정된 색상 알아내기
matplotlib 설치
소스코드)
#-*- coding: utf-8 -*-
'''
Created on 2018. 10. 3.
@author: Lee
'''
import matplotlib.pyplot as plt
from matplotlib import colors as mcolors
colors = dict(mcolors.BASE_COLORS, **mcolors.CSS4_COLORS)
# Sort colors by hue, saturation, value and name.
by_hsv = sorted((tuple(mcolors.rgb_to_hsv(mcolors.to_rgba(color)[:3])), name)
                for name, color in colors.items())
sorted_names = [name for hsv, name in by_hsv]
n = len(sorted_names)
ncols = 4
nrows = n // ncols
fig, ax = plt.subplots(figsize=(12, 10))
# Get height and width
X, Y = fig.get_dpi() * fig.get_size_inches()
h = Y / (nrows + 1)
w = X / ncols
for i, name in enumerate(sorted_names):
    row = i % nrows
    col = i // nrows
    y = Y - (row * h) - h
    xi_line = w * (col + 0.05)
    xf_line = w * (col + 0.25)
    xi_text = w * (col + 0.3)
    ax.text(xi_text, y, name, fontsize=(h * 0.4),
            horizontalalignment='left',
            verticalalignment='center')
    ax.hlines(y + h * 0.1, xi_line, xf_line,
              color=colors[name], linewidth=(h * 0.4))
ax.set_xlim(0, X)
ax.set_ylim(0, Y)
ax.set_axis_off()
fig.subplots_adjust(left=0, right=1,
                    top=1, bottom=0,
                    hspace=0, wspace=0)
plt.show()
결과
추가 이름있는 색상
'랭귀지 > python' 카테고리의 다른 글
| [ python] Extract sentences with specific words in a text file (0) | 2018.10.05 | 
|---|---|
| python 필요없는 문자, 특수문자, 공백 제거는 정규식 (0) | 2018.10.04 | 
| Python 슬라이싱으로 문자열 나누기 (0) | 2018.10.02 | 
| Python type() Check Python data type (0) | 2018.10.01 | 
| Python split() join() (0) | 2018.09.29 | 
			  Comments