-
Notifications
You must be signed in to change notification settings - Fork 1
/
04_plotly_06.py
52 lines (46 loc) · 1.2 KB
/
04_plotly_06.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# Bar Charts
# Stacked Bar Charts
# Nested Bar Charts
# Presents categorical data with rectangular bars with heights (or lengths) propotional to the values that they represent.
import plotly.offline as pyo
import plotly.graph_objs as go
import pandas as pd
df = pd.read_csv('data/2018WinterOlympics.csv')
data = []
# Simple Barchart
# trace = go.Bar(
# x=df['NOC'],
# y=df['Total'],
# )
# data.append(trace)
# Nested Barchart
trace1 = go.Bar(
x=df['NOC'],
y=df['Gold'],
name='Gold',
marker=dict(
color='#FFD700'
)
)
data.append(trace1)
trace2 = go.Bar(
x=df['NOC'],
y=df['Silver'],
name='Silver',
marker=dict(
color='#9EA0A1'
)
)
data.append(trace2)
trace3 = go.Bar(
x=df['NOC'],
y=df['Bronze'],
name='Bronze',
marker=dict(
color='#CD7F32'
)
)
data.append(trace3)
layout = go.Layout(title='Medals', barmode='stack')
fig = go.Figure(data=data,layout=layout)
pyo.plot(fig, filename='04_plotly_06.html')