import plotly.graph_objects as go
= go.Figure()
fig
# Create scatter trace of text labels
fig.add_trace(go.Scatter(=[6, 6, 6],
x=[1, 3, 5],
y=["Line",
text"Dashed Line",
"Dotted Line"],
="text",
mode
))
# Add shapes
type="line",
fig.add_shape(=1, y0=1, x1=5, y1=1,
x0=dict(color="RoyalBlue",width=3)
line
)
type="line",
fig.add_shape(=1, y0=3, x1=5, y1=3,
x0=dict(
line="LightSeaGreen",
color=4,
width="dashdot",
dash
)
)
type="line",
fig.add_shape(=1, y0=5, x1=5, y1=5,
x0=dict(
line="MediumPurple",
color=4,
width="dot",
dash
)
)
# Set axes ranges
range=[0, 8])
fig.update_xaxes(range=[0, 6])
fig.update_yaxes(
fig.show()
Plotly line, shape 그리기
Plotly line, shape 그리기
Data Visualization
Plotly line, shape를 그리는 방법에 대해서 정리합니다.
Plotly line, shape 그리기
Ploty로 line과 shape를 그리는 방법을 정리합니다.
Line 그리는 방법
add_shape
함수로 line을 그리는 코드입니다.
line은 add_shape
함수를 사용합니다. 라인의 스타일은 line
변수에 딕셔너리 형식으로 정보를 전달합니다. 딕셔너리의 dash
는 라인의 형태를 결정하고 dashdot
, dot
, line
으로 설정할 수 있습니다.
직사각형을 그리는 방법
add_shape
함수로 직사각형을 그리는 코드입니다.
import plotly.graph_objects as go
= go.Figure()
fig
fig.add_trace(go.Scatter(=[1.5, 4.5],
x=[0.75, 0.75],
y=["Unfilled Rectangle", "Filled Rectangle"],
text="text",
mode
))
# Set axes properties
range=[0, 7], showgrid=False)
fig.update_xaxes(range=[0, 3.5])
fig.update_yaxes(
# Add shapes
type="rect",
fig.add_shape(=1, y0=1, x1=2, y1=3,
x0=dict(color="RoyalBlue"),
line
)type="rect",
fig.add_shape(=3, y0=1, x1=6, y1=2,
x0=dict(
line="RoyalBlue",
color=2,
width
),="LightSkyBlue",
fillcolor
)dict(xref='x', yref='y'))
fig.update_shapes( fig.show()
이번엔 add_shape
함수에 type
으로 전달하는 정보를 rect
로 전달해서 직사각형을 만들었습니다. 내부를 색으로 채울때는 fillcolor
를 사용했습니다.
투명도 조절하기
차트에 라인을 이용하여 원하는 위치를 지정하는 경우 투명도를 조정해서 차트의 정보를 유지하면 라인을 그릴 수 있습니다.
import plotly.graph_objects as go
= go.Figure()
fig
type="line",
fig.add_shape(=1, y0=1, x1=5, y1=1,
x0=0.5,
opacity=dict(
line="MediumPurple",
color=4,
width="dot",
dash
)
)
type="line",
fig.add_shape(=1, y0=2, x1=5, y1=2,
x0=0.7,
opacity=dict(
line="MediumPurple",
color=4,
width="dot",
dash
)
)
# Set axes ranges
range=[0, 6])
fig.update_xaxes(range=[0, 3])
fig.update_yaxes(
fig.show()
add_shape
함수에 opacity
를 추가로 전달합니다. opacity
가 1인 경우 투명도가 없이 표시되며 opacity
가 0인 경우 완전히 투명합니다.
Date | Title | Author |
---|---|---|
Jan 1, 3000 | 전체 카테고리 | |
Aug 18, 2024 | Folium에서 Google Map 사용 방법 | |
Aug 16, 2024 | Folium의 Choropleth 지도 | |
Aug 15, 2024 | Folium 마커 생성과 색상 변경하기 | |
Oct 5, 2023 | Plotly Funnel(깔대기) 차트 만들기 | |
Oct 4, 2023 | Plotly 차트의 축 tick 회전 및 폰트 변경하기 | |
Oct 3, 2023 | Plotly 불릿차트 | |
Oct 2, 2023 | Plotly Hover 설정하기 | |
Sep 30, 2023 | Plotly Axis 포멧 변경하기 | |
Sep 28, 2023 | Plotly 마커 모양 변경하기 | |
Sep 25, 2023 | Plotly Time Series 날짜 범위 UI 사용하기 | |
Sep 22, 2023 | Plotly Line Plot만들기 | |
Sep 21, 2023 | Plotly Histogram Plot만들기 | |
Sep 18, 2023 | Plotly Animation 만들기 | |
Sep 18, 2023 | Plotly Box Plot만들기 | |
Sep 17, 2023 | Plotly Treemap 만들기 | |
Sep 17, 2023 | Plotly Bubble chart 만들기 | |
Sep 13, 2023 | Plotly Subpolt 만들기 |
No matching items