In [ ]:
# import packages
import plotly.offline as pyo
import plotly.graph_objects as go
import pandas as pd
In [ ]:
# read in mocksurvey.csv
df = pd.read_csv("./../data/mocksurvey.csv", index_col=0)
df
Out[ ]:
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
In [ ]:
# Create data list
data = [
    go.Bar(
        y=df.index, 
        x=df[response], 
        name=response,
        orientation="h",
        )
    for response in df.columns
    ]
In [ ]:
# create layout
layout = go.Layout(
    title="Bar Chart"
)
In [ ]:
# create fig
fig = go.Figure(data=data, layout=layout)
In [ ]:
# load chart into html
# pyo.plot(fig, filename="bar_chart_exercise.html")
In [ ]:
# load chart in this notebook
pyo.iplot(fig, filename="bar_chart_exercise.html")