





def drawGraph():
plt.figure(figsize=(10, 6))
plt.plot(t, np.sin(t), label="sin") # 선 데이터 의미 구분
plt.plot(t, np.cos(t), label="cos")
plt.grid(True) # 격자무늬 추가 / False: 격자 무늬 없앰
plt.legend(loc=3) # 라벨 위치 바꾸기
plt.title("example of sinewave") # 그래프 제목
plt.xlabel("time") # x축, y축 이름 지어주기
plt.ylabel("amplitude")# amplitude : 진폭
plt.show()
drawGraph()

def drowGraph():
plt.figure(figsize=(10, 6))
plt.plot(
t,
y,
color="green",
linestyle="dashed", ## -- 표현 가능
marker="o",
markerfacecolor="blue",
markersize=15
)
plt.xlim([-0.5, 6.5])
plt.ylim([0.5, 9.5])
plt.show()
drowGraph()

t = np.array(range(0, 10)) # array 행렬 데이터
y = np.array([9, 8, 7, 9, 8, 3, 2, 4, 3, 4])
def drawGraph():
plt.figure(figsize=(10, 6))
plt.scatter(t, y)
plt.show()
drawGraph()

colormap = t
def drawGraph():
plt.figure(figsize=(20, 6))
plt.scatter(t, y, s=50, c=colormap, marker="<")
plt.colorbar()
plt.show()
drawGraph()

def drawGraph():
plt.figure(figsize=(14, 10))
plt.scatter(data_result["인구수"], data_result["소계"], s=50)
plt.xlabel("인구수")
plt.ylabel("CCTV")
plt.grid(True)
plt.show()
drawGraph()

np.polyfit() : 직선을 구성하기 위한 계수를 계산
np.poly1d : polyfit으로 찾은 계수로 파이썬에서 사용할 수 있는 함수로 만들어주는 기능

인구가 40만인 구에서 서울시의 전체 경향에 맞는 적당한 CCTV 수는?

경향선을 그리기 위한 x 데이터 생성
np.linespace(a,b,n) : a부터 b까지 n개의 등간격 데이터 생성
def drawGraph():
plt.figure(figsize=(14, 10))
plt.scatter(data_result["인구수"], data_result["소계"], s=50)
plt.plot(fx, f1(fx), ls="--", lw=3, color="g")
plt.xlabel("인구수")
plt.ylabel("CCTV")
plt.grid(True)
plt.show()
drawGraph()




“이 글은 제로베이스 데이터 취업 스쿨의 강의 자료 일부를 발췌하여 작성되었습니다.”