시각화 하기

장상희·2025년 6월 9일
0

파이썬

목록 보기
30/31

부산광역시 인구 빅데이터

fig = px.bar(df, x =' 구분 ',y = '  세대수  ', title = '부산광역시 인구현황')
fig.show()

기본적인 동별 세대수

image.png

동별 남,여 인구수

fig = go.Figure()

fig = make_subplots(rows=1,cols=2)
fig.add_trace(go.Bar(x=df[' 구분 '],y=df['  인구수(남)  '],name = "인구(남)"),row=1,col=1)
fig.add_trace(go.Bar(x=df[' 구분 '],y=df['  인구수(여)  '],name = "인구(여)"),row=1,col=2)

fig.update_xaxes(tickangle=45, row=1, col=1)#tick angle = 눈금 각도, 글자의 각도를 수정할 수 있게 해준다
fig.update_xaxes(tickangle=45, row=1, col=2)

fig.show()

image.png

부산동별 세대수 원그래프 시각화

fig = px.pie(df, values = '  세대수  ',names = ' 구분 ')
fig.update_layout(title = "부산동별 세대수")
fig.show()

image.png

꺾은 선

fig = px.scatter(df, x = ' 구분 ', y = '  세대수  ')
fig.add_trace(go.Scatter(x=df[' 구분 '],y=df['  세대수  '])name="세대수")

fig.update_xaxes(tickangle=0)
fig.show()

image.png

동별 인구를 4분활로 출력하기

fig = go.Figure()

fig = make_subplots(rows=2,cols=2, subplot_titles=("인구수(남)","인구수(여)","18세이상인구수(남)","18세이상인구수(여)"))
fig.add_trace(go.Bar(x=df[' 구분 '],y=df['  인구수(남)  '],name = "인구(남)"),row=1,col=1)
fig.add_trace(go.Bar(x=df[' 구분 '],y=df['  인구수(여)  '],name = "인구(여)"),row=1,col=2)
fig.add_trace(go.Bar(x=df[' 구분 '],y=df['  18세이상인구수(남)  '],name = "18세이상인구(남)"),row=2,col=1)
fig.add_trace(go.Bar(x=df[' 구분 '],y=df['  18세이상인구수(여)  '],name = "18세이상인구(여)"),row=2,col=2)
fig.update_xaxes(tickangle=45, row=1, col=1)#tick angle = 눈금 각도, 글자의 각도를 수정할 수 있게 해준다
fig.update_xaxes(tickangle=45, row=1, col=2)
fig.update_xaxes(tickangle=45,row=2,col=1)
fig.update_xaxes(tickangle=45,row=2,col=2)
fig.update_layout(title_text="부산인구현황",)
fig.show()

image.png

scatter도 같이

fig = go.Figure()

fig = make_subplots(rows=2,cols=2, subplot_titles=("인구수(남)","인구수(여)","18세이상인구수(남)","18세이상인구수(여)"))
fig.add_trace(go.Bar(x=df[' 구분 '],y=df['  인구수(남)  '],name = "인구(남)"),row=1,col=1)
fig.add_trace(go.Bar(x=df[' 구분 '],y=df['  인구수(여)  '],name = "인구(여)"),row=1,col=2)
fig.add_trace(go.Scatter(x=df[' 구분 '],y=df['  18세이상인구수(남)  '],name = "18세이상인구(남)"),row=2,col=1)
fig.add_trace(go.Scatter(x=df[' 구분 '],y=df['  18세이상인구수(여)  '],name = "18세이상인구(여)"),row=2,col=2)
fig.update_xaxes(tickangle=45, row=1, col=1)#tick angle = 눈금 각도, 글자의 각도를 수정할 수 있게 해준다
fig.update_xaxes(tickangle=45, row=1, col=2)
fig.update_xaxes(tickangle=45,row=2,col=1)
fig.update_xaxes(tickangle=45,row=2,col=2)
fig.update_layout(title_text="부산인구현황",)
fig.show()

image.png

그래프 겹쳐서 출력

fig = px.scatter(df, x = ' 구분 ', y = '  인구수(계)  ')
fig.add_trace(go.Scatter(x=df[' 구분 '],y=df['  인구수(계)  '],mode='lines+markers',name='인구수'))
fig.add_trace(go.Scatter(x=df[' 구분 '],y=df['  65세이상인구수(계)  '],mode='lines+markers',name='65세이상인구수'))
fig.add_trace(go.Scatter(x=df[' 구분 '],y=df['  18세이상인구수(계)  '],mode='lines+markers',name='18세이상인구수'))
fig.update_xaxes(tickangle=0)
fig.update_layout(title = "총인구수 및 18,65세이상인구수")
fig.show()

image.png

그래프 크기 조절

fig = make_subplots(rows=2,cols=2,  column_widths=[0.3, 0.7], row_heights =[0.7, 0.3], subplot_titles=("인구수(남)","인구수(여)","18세이상인구수(남)","18세이상인구수(여)"))
fig.add_trace(go.Bar(x=df[' 구분 '],y=df['  인구수(남)  '],name = "인구(남)"),row=1,col=1)
fig.add_trace(go.Bar(x=df[' 구분 '],y=df['  인구수(여)  '],name = "인구(여)"),row=1,col=2)
fig.add_trace(go.Scatter(x=df[' 구분 '],y=df['  18세이상인구수(남)  '],name = "18세이상인구(남)"),row=2,col=1)
fig.add_trace(go.Scatter(x=df[' 구분 '],y=df['  18세이상인구수(여)  '],name = "18세이상인구(여)"),row=2,col=2)
fig.update_xaxes(tickangle=45, row=1, col=1)#tick angle = 눈금 각도, 글자의 각도를 수정할 수 있게 해준다
fig.update_xaxes(tickangle=45, row=1, col=2)
fig.update_xaxes(tickangle=45,row=2,col=1)
fig.update_xaxes(tickangle=45,row=2,col=2)
fig.update_layout(title_text="부산인구현황",)
fig.show()

image.png

세대수가 가장 많은 동에서 가장 적은 동 사이에 사각영역 추가

fig = px.scatter(df, x = ' 구분 ', y = '  세대수  ')
fig.add_vrect(x0=1, x1=5, line_width=0, fillcolor="white", opacity=0.5,
              annotation_text="편차가 크다", 
              annotation_position="bottom right",
              annotation_font_size=10,
              annotation_font_color="black",
              annotation_font_family="Times New Roman")
fig.add_trace(go.Scatter(x=df[' 구분 '],y=df['  세대수  '],name="세대수"))
fig.update_layout(title = "동별 세대수")
fig.update_xaxes(tickangle=0)
fig.show()

image.png

Table시각화

fig = go.Figure()
fig.add_trace(
    go.Table(header=dict(values=["세대수","인구수","인구수(남)","인구수(여)"]), #헤더
             cells=dict(values=[df['  세대수  '], # 1열
                                df['  인구수(계)  '],
                                df['  인구수(남)  '],
                                df['  인구수(여)  ']]))) # 2열
fig.update_layout(title ="Table")
fig.show()

image.png

profile
프로그래머 꿈나무

0개의 댓글