반응형

출처: http://stackoverflow.com/questions/20105364/how-can-i-make-a-scatter-plot-colored-by-density-in-matplotlib

 

python matplotlib를 이용해서 scatter plot을 그리는 데 밀도도 반영하고 싶다면 아래와 같이 하면 됨

 

import numpy as np
import matplotlib.pyplot as plt
from scipy.stats import gaussian_kde


# 출력할 x,y 좌표 랜덤하게 생성
x = np.random.normal(size=1000)
y = x * 3 + np.random.normal(size=1000)


# 좌표에 대한 밀도를 계산하는 부분
xy = np.vstack([x,y])
z = gaussian_kde(xy)(xy)


fig, ax = plt.subplots()


#색깔은 z에 따라서, 점의 크기는 100으로
ax.scatter(x, y, c=z, s=100, edgecolor='')
plt.show()

 

 

참고: http://stackoverflow.com/questions/24976239/axis-limits-for-scatter-plot-matplotlib

 

plt.xlim(-1,1)
plt.ylim(-1,1) 

 

- 이용해서 축의 범위를 정할 수 있음 (추후 확인해보기!)

 

참고: http://stackoverflow.com/questions/9622163/save-plot-to-image-file-instead-of-displaying-it-using-matplotlib-so-it-can-be

 

fig.savefig('/path/image.png')

 

- plot 결과를 이미지 파일로 저장할 수 있음

 

출처 : http://blog.bharatbhole.com/creating-boxplots-with-matplotlib/

 

- python에서 boxplot 그리기

반응형

+ Recent posts