In [23]:
import pandas as pd
import numpy as np
import plotly.plotly as py
import plotly.graph_objs as go
df = pd.read_csv("https://raw.githubusercontent.com/democratia/political_science/master/Interkantonale-Korrelation/alle-volksabstimmungen-resultate.csv", sep=";")
data = df[list(df.columns[2:-1])]
kantonsnamen = list(df)[2:-1]
print(kantonsnamen)
data_mat = data.as_matrix()
kantone = data_mat[:, 1:]
In [24]:
covariance = np.corrcoef(kantone.T)
trace = go.Heatmap(
z=covariance,
x=kantonsnamen,
y=kantonsnamen)
layout = go.Layout(
title='Interkantonale Korrelationen',
)
data=[trace]
fig = go.Figure(data=data, layout=layout)
py.iplot(fig, filename='interkantonale-korrelationen')
Out[24]:
In [ ]: