python plotly - bar

BackEnd_Ash.log·2021년 1월 7일
0

파이썬

목록 보기
25/34

start

#######
# This is a stacked bar chart showing three traces
# (gold, silver and bronze medals won) for each country
# that competed in the 2018 Winter Olympics.
######
import plotly.offline as pyo
import plotly.graph_objs as go
import pandas as pd

df = pd.read_csv('../data/2018WinterOlympics.csv')

trace1 = go.Bar(
    x=df['NOC'],  # NOC stands for National Olympic Committee
    y=df['Gold'],
    name = 'Gold',
    marker=dict(color='#FFD700') # set the marker color to gold
)
trace2 = go.Bar(
    x=df['NOC'],
    y=df['Silver'],
    name='Silver',
    marker=dict(color='#9EA0A1') # set the marker color to silver
)
trace3 = go.Bar(
    x=df['NOC'],
    y=df['Bronze'],
    name='Bronze',
    marker=dict(color='#CD7F32') # set the marker color to bronze
)
data = [trace1, trace2, trace3]
layout = go.Layout(
    title='2018 Winter Olympic Medals by Country',
    barmode='stack'
)
fig = go.Figure(data=data, layout=layout)
pyo.plot(fig, filename='bar3.html')

import

import plotly.offline as pyo
import plotly.graph_objs as go
import pandas as pd

trace

trace1 = go.Bar(
    x=df['NOC'],  # NOC stands for National Olympic Committee
    y=df['Gold'],
    name = 'Gold',
    marker=dict(color='#FFD700') # set the marker color to gold
)

이렇게 trace 를 여러개 만들 수도 있다.
그리고 data 라는 리스트를 만들어서 trace 들을 담아둔다.

data = [trace1 , trace2 , trace3 ]

layout

layout = go.Layout(
    title='2018 Winter Olympic Medals by Country',
    barmode='stack'
)

이름을 정하고 , bar 중에서 어떻게 보여줄것인지
barmode 를 통해서 정한다.

fig = go.Figure(data=data, layout=layout)
pyo.plot(fig, filename='bar3.html')
profile
꾸준함이란 ... ?

0개의 댓글