In [1]:
import plotly.plotly as py
import plotly.graph_objs as go
import pandas as pd

import numpy as np

importdata = pd.read_csv('https://raw.githubusercontent.com/democratia/political_science/master/Daten/ja-prozent.csv', sep=";")

In [14]:
hist_data = {}
kantonsnamen = list(importdata)[2:]
n_histograms = len(kantonsnamen)
traces = []
buttons = []
for i, c in zip(range(n_histograms), kantonsnamen):
    vis = False
    if i == 0:
        vis = True
    traces.append(go.Histogram(
        x=importdata[c].values,
        opacity=0.75,
        autobinx=False,
        xbins=dict(
            start=0,
            end=100,
            size=5
        ),
        text="",
        name="",
        visible=vis
    ))
    visible_list = [False]*27
    visible_list[i] = True
    buttons.append(
        dict(
            args=['visible', visible_list],
            label=c,
            method='restyle'
        ))
data = traces
layout = go.Layout(barmode='overlay',
    updatemenus=list([
        dict(
            active=0,
            x=-0.05,
            y=1,
            yanchor='top',
            buttons=buttons
        )
    ]),
    title='Histogramm Anzahl Abstimmungen nach Prozent Ja Stimmen',
    xaxis=dict(title='Prozent Ja Stimmen'),
    yaxis=dict(title='Anzahl Abstimmungsresultate')
)
fig = go.Figure(data=data, layout=layout)

py.iplot(fig, filename='results-histogram')


Out[14]:

In [ ]: