-
Notifications
You must be signed in to change notification settings - Fork 0
/
DivergingStackedBar.py
37 lines (34 loc) · 1.17 KB
/
DivergingStackedBar.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
import numpy as np
import pandas as pd
import plotly.graph_objects as go
d = {'Who': ['A', 'B', 'C', 'D', 'E', 'F'],
'Pants on Fire': [9,7,6,4, 2, 1],
'False': [7, 6, 4, 5, 2,1],
'Mostly False': [5, 4, 6,4, 2, 6],
'Half True' : [4,2,5,6,3, 2],
'Mostly True': [5,3,2,3,4,3],
' True': [2,4,3,6, 6, 8]}
df = pd.DataFrame(d)
fig = go.Figure()
for col in df.columns[1:4]:
fig.add_trace(go.Bar(x=-df[col].values,
y=df['Who'],
orientation='h',
name=col,
customdata=df[col],
hovertemplate = "%{y}: %{customdata}"))
for col in df.columns[4:]:
fig.add_trace(go.Bar(x= df[col],
y =df['Who'],
orientation='h',
name= col,
hovertemplate="%{y}: %{x}"))
fig.update_layout(barmode='relative',
height=400,
width=700,
yaxis_autorange='reversed',
bargap=0.01,
legend_orientation ='h',
legend_x=-0.05, legend_y=1.1
)
fig.show()