앞선 글에서 Scatter Traces를 통해서 chart를 생성했다면 기본 trace에 나만의 style를 표현하고 싶을 것 같습니다.
본 페이지에서는 lines trace의 선 모양이나 두께 변경하여 style를 가미하는 방법을 알려드리겠습니다.
*key: line, line_dash, line_width 정보 참조
line
Code: fig.update_traces(line=dict(...), selector=dict(type='scatter'))
Type: dict containing one or more of the keys listed below.
dash
Code: fig.update_traces(line_dash=<VALUE>, selector=dict(type='scatter'))
Type: string
Default: "solid"
Sets the dash style of lines. Set to a dash type string ("solid", "dot", "dash", "longdash", "dashdot", or "longdashdot") or a dash length list in px (eg "5px,10px,2px,2px").
width
Code: fig.update_traces(line_width=<VALUE>, selector=dict(type='scatter'))
Type: number greater than or equal to 0
Default: 2
Sets the line width (in px).
line_dash
*dash 추가 설명
The 'dash' property is an enumeration that may be specified as:
- One of the following dash styles:
['solid', 'dot', 'dash', 'longdash', 'dashdot', 'longdashdot']
- A string containing a dash length list in pixels or percentages
(e.g. '5px 10px 2px 2px', '5, 10, 2, 2', '10% 20% 40%', etc.)
code: go.Scatter의 line_dash의 'dot' 스타일, line의 dict containing 구조로 dash의 'dash' 스타일로 변경
import plotly
import plotly.graph_objects as go
x1 = [ 1, 2, 3, 4, 5 ]
y1 = [ 1, 5, 4, 8, 11 ]
x2 = [ 1, 2, 3, 4, 5 ]
y2 = [ 10, 9, 6, 3, 0 ]
fig = go.Figure()
trace1 = go.Scatter( x=x1, y=y1, mode='lines', line_dash="dot" )
trace2 = go.Scatter( x=x2, y=y2, mode='lines', line=dict(dash="dash") )
fig.add_trace( trace1 )
fig.add_trace( trace2 )
fig.show()
output

line_width
code: go.Scatter의 line_width 혹은 line의 dict containing 구조로 width의 값을 value로 적용
import plotly
import plotly.graph_objects as go
x1 = [ 1, 2, 3, 4, 5 ]
y1 = [ 1, 5, 4, 8, 11 ]
x2 = [ 1, 2, 3, 4, 5 ]
y2 = [ 10, 9, 6, 3, 0 ]
fig = go.Figure()
trace1 = go.Scatter( x=x1, y=y1, mode='lines', line_dash="dashdot", line_width=4 )
trace2 = go.Scatter( x=x2, y=y2, mode='lines', line=dict(dash="longdash", width=10) )
fig.add_trace( trace1 )
fig.add_trace( trace2 )
fig.show()
output

추가적인 정보는 "Python Figure Reference: scatter Traces" 페이지를 참고 부탁드립니다.