
Youtube 이수안컴퓨터연구소의
Plotly 한번에 끝내기 - 모던한 인터렉티브 시각화 라이브러리 동영상을 보고 요약한 코드입니다!
import plotly.io as pio
import plotly.express as px
import plotly.graph_objects as go
import plotly.figure_factory as ff
from plotly.subplots import make_subplots
from plotly.validators.scatter.marker import SymbolValidator
# 병렬 다이어그램 (Parallel Diagram)
# px.parallel_categories
fig = px.parallel_categories(
data,
dimensions = [], # 보고 싶은 데이터만 입력,
color = ,
color_continuous_scale = , # px.colors.sequential.Viridis
)
fig.show()
# px.parallel_coordinates
fig = px.parallel_coordinates(
data,
color = ,
dimensions = [],
color_continuous_scale = , # px.colors.diverging.Armyrose
color_continous_midpoint = , # 2
)
fig.show()
# 덴드로그램 (Dendrogram)
# ff.create_dendrogram
fig = ff.create_dendrogram(
x = ,
color_threshold = , # 덴드로그램 색깔 바뀌는 기준, 1.2
)
fig.update_layout(
width = ,
height =
)
fig.show()
# 맵 (maps)
# px.scatter_mapbox
fig = px.scatter_mapbox(
data,
lat = ,
lon = ,
color = ,
size = , size_max = ,
color_continous_scale = , # px.colors.cyclical.Edge,
mapbox_style = , # 스타일, carto-positron
)
fig.show()
# px.line_mapbox
fig = px.line_mapbox(
data,
lat = ,
lon = ,
color = ,
zoom = ,
height = ,
width =
)
fig.update_layout(
mapbox_style = , # stamen-terrain
mapbox_zoom = ,
mapbox_center_lat = ,
margin = {'r':, 't':, 'l':, 'b':}
)
fig.show()
# px.density_mapbox
fig = px.density_mapbox(
earthquake,
lat = ,
lon = ,
z = ,
radius = , # 10
center = dict(
lat = ,
lon =
),
zoom = ,
mapbox_style = # stamen-terrain
)
fig.show()
# px.choropleth_mapbox
fig = px.choropleth_mapbox(
data,
geojson = , # json 파일 다운로드
location = ,
color = ,
color_continous_scale = , # blues
range_color = , # color range 설정 (0, 12)
mapbox_style = , # carto-positron
zoom = ,
center = {'lat' : , 'lon' : },
opacity = ,
labels = {'' : ''},
)
fig.update_layout(
margin = {'r' : , 't' : , 'l' : , 'b' : } # 마진 설정
)
fig.show()
# px.choropleth
fig = px.choropleth(
data,
locations = ,
color = ,
hover_name = ,
color_continous_scale = , # px.colors.sequential.Viridis
animation_frame = , # animation 추가
)
fig.show()
# go.Choropleth
fig = go.Figure(data=go.Choropleth(
locations = ,
z = ,
text = ,
colorscale = , # solar_r
autocolorscale = , # False
reversescale = , # True
marker_line_color = , # darkgray
marker_line_width = , # .5
colorbar_tickprefix = , # %
colorbar_title =
))
fig.update_layout(
title_text = ,
geo = dict(
showframe = , # False
showcoastlines = , # False
projection_type = # equirectangular
)
)
fig.show()
# 지구본
# go.Scattergeo
fig = go.Figure(go.Scattergeo())
fig.update_geos(
projection_type = , # orthographic/natural earth
)
fig.update_layout(
height = ,
margin = {'r':, 't':, 'l':, 'b'}
)
fig.show()
# px.line_geo
fig = px.line_geo(
data,
locations = ,
color = ,
projection = , # orthographic
)
fig.show()
# px.scatter_geo
fig = px.scatter_geo(
data,
locations = ,
color = ,
hover_name = ,
size = ,
projection = , # natural_earth
animation_frame = , # animation 추가
)
fig.show()
# 3D 차트
# px.line_3d
fig = px.line_3d(
data,
x = ,
y = ,
z = ,
color =
)
fig.show()
# px.scatter_3d
fig = px.scatter_3d(
data,
x = ,
y = ,
z = ,
color = ,
symbol = ,
size = ,
opacity = ,
hover_data = []
)
fig.update_layout(
scene_zaxis_type = 'log' # bubble 차트 만들 수 있음
)
fig.show()