# import packages
import plotly.offline as pyo
import plotly.graph_objects as go
import pandas as pd
# read in mocksurvey.csv
df = pd.read_csv("./../data/mocksurvey.csv", index_col=0)
df
Strongly Agree | Somewhat Agree | Neutral | Somewhat Disagree | Strongly Disagree | |
---|---|---|---|---|---|
Question 1 | 0.45 | 0.25 | 0.10 | 0.12 | 0.08 |
Question 2 | 0.12 | 0.07 | 0.48 | 0.18 | 0.15 |
Question 3 | 0.05 | 0.22 | 0.19 | 0.23 | 0.31 |
# Create data list
data = [
go.Bar(
y=df.index,
x=df[response],
name=response,
orientation="h",
)
for response in df.columns
]
# create layout
layout = go.Layout(
title="Bar Chart"
)
# create fig
fig = go.Figure(data=data, layout=layout)
# load chart into html
# pyo.plot(fig, filename="bar_chart_exercise.html")
# load chart in this notebook
pyo.iplot(fig, filename="bar_chart_exercise.html")