코딩/기타
plotly 사용 예시(그래프)
자본왕김민춘
2023. 3. 19. 22:22
반응형
histogram
import plotly.express as px
df = px.data.tips()
fig = px.histogram(data_frame=df,
x="total_bill",
nbins=30, #가로 범위
color = "sex") #seaborn에서 hue와 같다. 성별 2종류로 구분하여 표현
fig.show() #show를 해야 표현 가능
import plotly.express as px
df = px.data.tips()
fig = px.box(df, x="day", y="total_bill", color="smoker", notched=True)
fig.show()
ganttchart(프로젝트 일정관리)
# gantt chart
import plotly.express as px
import pandas as pd
df = pd.DataFrame([
dict(Task="Job A", Start='2009-01-01', Finish='2009-02-28', Resource="Alex"),
dict(Task="Job B", Start='2009-03-05', Finish='2009-04-15', Resource="Alex"),
dict(Task="Job C", Start='2009-02-20', Finish='2009-05-30', Resource="Max")
])
fig = px.timeline(df, x_start="Start", x_end="Finish", y="Resource", color="Resource")
fig.show()
funnel chart
# funnel chart
import plotly.express as px
data = dict(
number=[39, 27.4, 20.6, 11, 2],
stage=["Website visit", "Downloads", "Potential customers", "Requested price", "Invoice sent"])
fig = px.funnel(data, x='number', y='stage')
fig.show()
election map
# election map
import plotly.express as px
df = px.data.election()
geojson = px.data.election_geojson()
fig = px.choropleth_mapbox(df, geojson=geojson, color="Bergeron",
locations="district", featureidkey="properties.district",
center={"lat": 45.5517, "lon": -73.7073},
mapbox_style="carto-positron", zoom=9)
fig.show()
※출처 : 패스트캠퍼스 김용담강사
반응형