
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
# px.bar
fig = px.bar(
data, x = , y = ,
hover_data = [], # hover시 보이는 데이터 지정 가능
color = ,
height = , # 높이
barmode = '', # group,
facet_row, facet_col,
category_orders = {'', [], '', []}, # facet에 따른 category 순서 지정
orientation = , # 'h' bar 방향
)
fig.show()
# animation
fig = px.bar(
data, x=, y=,
color = ,
animation_frame = '', # 애니메이션 변하는 기준 (재생버튼 부분)
animation_group = '' # column 이름
range_y = [0, ..]
)
fig.show()
# go.Bar
fig = go.Figure()
fig.add_trace(go.Bar(
data, x=, y=,
width= , # bar 너비
base = [], # default로 0, bar 시작점
marker_color = ,
name =
))
fig.update_layout(
barmode = '', # relative/stack/group
xaxis = {'categoryorder' : '', # 순서 정렬, category ascending/total descending/array
'categoryarray' : []}, # 'array'로 지정하면 순서 수동으로 정렬
)
fig.show()
# error bar
fig = go.Figure()
fig.add_trace(go.Bar(
data, x=, y=,
error_y = dict(
type = '', # data/percent
array = [], # error바 높이
arrayminus = [], # 길이 조정
value = , # array 없이 길이 정함/percent와 쓰임
valueminus = , # value와 쓰임
symmetric=, # True/False
visible=True
),
error_x = , # error_y 참조
))
fig.update_layout()
fig.show()
# 수동으로 색깔 지정하고 싶을 때
colors = ['', ] * 5
colors[1] = ''
colors[2] = ''
fig = go.Figure()
fig.add_trace(go.Bar(
data, x=, y=,
marker_color = colors
))
fig.update_layout()
fig.show()