# colorbar legend
x = np.linspace(0, 20, 100)
I = np.cos(x) - np.cos(x[:, np.newaxis])
I
# plt.imshow : 숫자를 이미지로 나타내주는 함수
plt.imshow(I)
# colorbar legend
plt.colorbar();
# cmap : color map
plt.imshow(I, cmap='Blues')
# colorbar legend
plt.colorbar();
# cmap 구획 나누기
plt.imshow(I, cmap=plt.cm.get_cmap('Blues', 5))
# colorbar legend
plt.colorbar();
# RdBu : red, blue
plt.imshow(I, cmap='RdBu')
# colorbar legend
plt.colorbar();
##다중플롯
fig, ax = plt.subplots(3, 3, sharex='col', sharey='row')
# GridSpec : 그래프 공간 합치기
grid = plt.GridSpec(2, 3, wspace=0.4, hspace=0.4)
plt.subplot(grid[0,0])
plt.subplot(grid[0,1:])
plt.subplot(grid[1,:2])
plt.subplot(grid[1,2])
# 텍스트와 주석(Text and Annotation)
# 그래프 위 원하는 위치에 텍스트 입력하기
fig, ax = plt.subplots()
ax.axis([0, 10, 0, 10])
ax.text(3, 6, ". 좌표1(3,6)", transform=ax.transData) # 실제 데이터값
ax.text(0.2, 0.4, ". 좌표2(0.2, 0.4)", transform=ax.transAxes); # 축에 대한 비율
# ax.text(0.2, 0.2, ". transFigure(0.2, 0.2)", transform=fig.transFigure) # 전체 figure에 대한 비율
x = np.arange(1, 40)
y = x*1.1
plt.scatter(x, y, marker='.')
# 원하는 위치를 화살표로 표시하기
x = np.arange(1, 40)
y = x*1.1
plt.scatter(x, y, marker='.')
plt.axis('equal') # x축, y축 범위 넉넉하게
plt.annotate('interesting point', xy=(4, 5), xytext=(20, 10),
arrowprops=dict(shrink=0.05));
# xy : 점 위치
# xytext : 텍스트 위치
x1 = np.random.normal(30, 3, 100) # (loc=0.0, scale=1.0, size=None)
x2 = np.random.normal(20, 3, 100)
x3 = np.random.normal(10, 3, 100)
plt.plot(x1, label='p1')
plt.plot(x2, label='p2')
plt.plot(x3, label='p3')
plt.legend(bbox_to_anchor=(0, 1.02, 1., .102), loc=0, ncol=3,
mode='extend', borderaxespad=0.2)
plt.annotate('POINT 1', xy=(50,20), xytext=(5,40), arrowprops=dict(arrowstyle='->'))
plt.annotate('POINT 2', xy=(40,30), xytext=(40,35), arrowprops=dict(arrowstyle='->'))
# 축 눈금 로그 스케일
plt.axes(xscale='log', yscale='log')
ax = plt.axes()
ax.plot(np.random.randn(100).cumsum())
# plt.NullLocator() : x축과 y축 눈금 없애기
ax.yaxis.set_major_locator(plt.NullLocator())
ax.xaxis.set_major_locator(plt.NullLocator())
fig, ax = plt.subplots(3, 3, sharex=True, sharey=True)
x = np.linspace(-3, 3, 1000, endpoint=True)
y = np.sin(x)
plt.plot(x, y)
x = np.linspace(-3, 3, 1000, endpoint=True)
y = np.sin(x)
plt.plot(x, y)
# x축(bottom), y축(left) 위치 변경하기
ax = plt.gca()
ax.spines['bottom'].set_position(('data', 0))
ax.spines['left'].set_position(('data', 0))
'Crawling > 데이터 시각화' 카테고리의 다른 글
Matplotlib_막대 플롯(Bar plot) (0) | 2022.01.10 |
---|---|
Matplotlib_라인 플롯(Line Plot) (0) | 2022.01.10 |
데이터시각화_10가지_Geo chart (0) | 2022.01.06 |
데이터시각화_10가지_Box plot (0) | 2022.01.06 |
데이터시각화_10가지_Histogram (0) | 2022.01.06 |