Polar Plot
꼭 극 좌표계로만 그릴 필요는 없고, 직교 좌표계 X,Y에서 변환 가능
# polar coordinate 만들기
fig = plt.figure(figsize=(12,7)
ax = fig.add_subplot(111,polar=True) # projection='polar'
ax.set_rlabel_position(-90) # label 각도 조정
plt.show()
# 기본적인 polar chart
np.random.seed(19680801)
N = 100
r = 2 * np.random.rand(N)
theta = 2 * np.pi * np.random.rand(N)
area = 200 * r**2
colors = theta
fig = plt.figure()
ax = fig.add_subplot(111, projection='polar')
c = ax.scatter(theta, r, c=colors, s=area, cmap='hsv', alpha=0.75)
plt.show()
# line plot에 fill으로 색상 채우기
fig = plt.figure()
ax = fig.add_subplot(111, projection='polar')
ax.fill(theta, r)
plt.show()
Radar Plot
Polar plot을 잘 사용하고 싶을 때 사용하며, 극 좌표계를 사용하는 대표적인 차트
별 모양으로 생겨 Star Plot으로 불리기도 한다
중심점을 기준으로 N개의 변수 값을 표현할 수 있다.
데이터의 Quality를 표현하기에 좋다.
주의점!
parameter
theta = np.linespace(0,2*np.pi,6,endpoint=False)
fig = plt.figure()
ax = fig.add_subplot(111, projection='polar')
# 첫번째 데이터와 마지막 데이터를 이어주기 위해 추가
# 이것을 추가하지 않으면 마지막 선이 나타나지 않음
values.append(values[0])
theta = theta.tolist() + [theta[0]]
ax.plot(theta, values)
ax.fill(theta, values, alpha=0.5)
ax.set_thetagrids([n*60 for n in range(6)], stats)
ax.set_theta_offset(np.pi/2)
plt.show()
fig = plt.figure(figsize=(14, 4))
for idx in range(3):
# 여러개의 차트로 나타내기
# 이부분을 생략하면 겹쳐서 나타남
ax = fig.add_subplot(1,3,idx+1, projection='polar')
values = pokemon.iloc[idx][stats].to_list()
values.append(values[0])
ax.plot(theta, values, color='forestgreen')
ax.fill(theta, values, color='forestgreen', alpha=0.3)
ax.set_rmax(100)
ax.set_thetagrids([n*60 for n in range(6)], stats)
ax.set_theta_offset(np.pi/2)
plt.show()