Skip to content

Instantly share code, notes, and snippets.

@michalskop
michalskop / d3.scatterplot.js
Last active August 29, 2015 14:09
CZ: Praha 2010-2014 (WPCA, Python+R, reusable charts)
/* requires D3 + https://github.com/Caged/d3-tip */
d3.scatterplot = function() {
function scatterplot(selection) {
selection.each(function(d, i) {
//options
var data = (typeof(data) === "function" ? data(d) : d.data),
margin = (typeof(margin) === "function" ? margin(d) : d.margin),
axes = (typeof(axes) === "function" ? axes(d) : d.axes),
minmax = (typeof(minmax) === "function" ? minmax(d) : d.minmax),
size = (typeof(size) === "function" ? size(d) : d.size);
@michalskop
michalskop / csv2json.py
Last active August 29, 2015 14:07
CZ: Senate 2014, after elections
import csv
import json
lastgroup = ''
data = []
i = 0
dReader = csv.reader(open('data.csv'),delimiter=",")
for row in dReader:
if row[5].strip() != lastgroup:
if i != 0:
@michalskop
michalskop / binomial.js
Last active August 29, 2015 14:07
Multi-series line charts (comparison of libraries)
// calculates exact binomial confidence intervals (4 decimal digits)
// http://statpages.org/confint.html
function CalcBinL(x,N,vTL,vTU) {
vTL = typeof vTL !== 'undefined' ? vTL : 0.25;
vTU = typeof vTU !== 'undefined' ? vTU : 0.25;
var vx = x
var vN = N
var vP = vx/vN
P= vP
@michalskop
michalskop / cz.jpg
Last active August 29, 2015 14:07
CZ: Local elections 2014, 3 parties
cz.jpg
@michalskop
michalskop / calculation.py
Last active June 9, 2017 02:20
CZ: Local elections 2014
import json
from operator import itemgetter
import csv
with open("cz2014towns.json") as infile:
results = json.load(infile)
data = {}
datatotal = {}
for town in results:
@michalskop
michalskop / index.html
Last active August 29, 2015 14:07
CZ: Senate, Praha 10, 2014
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<!--<script src="d3.v3.js"></script>-->
<script src="http://d3js.org/d3.v3.min.js"></script>
<link href="//netdna.bootstrapcdn.com/font-awesome/4.0.3/css/font-awesome.css" rel="stylesheet"> <!-- note: http://stackoverflow.com/questions/20032426/fontawesome-doesnt-display-in-firefox -->
</head>
@michalskop
michalskop / csv2json.py
Last active August 29, 2015 14:06
CZ: Senate, towards elections 2014
import csv
import json
lastgroup = ''
data = []
i = 0
dReader = csv.reader(open('data.csv'),delimiter=",")
for row in dReader:
if row[5].strip() != lastgroup:
if i != 0:
@michalskop
michalskop / ba-2010.png
Last active August 29, 2015 14:06
BA: Elections 2010
ba-2010.png
@michalskop
michalskop / algorithm.py
Last active November 22, 2020 12:52
Hemicycle chart (general)
# calculates optimal numbers of representives for hemicycle chart
import math
import csv
import numpy as np
import timeit
start = timeit.default_timer()
#benchmark:
#n0 = 200 : 4:23s, 5:52s, 6:132s, 7:285s, 8:579s, 9:1167s , 10:2342s, 11: 4632s
@michalskop
michalskop / distribution.svg
Last active August 29, 2015 14:04
CZ: Salary distribution (FontAwesome chart)
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.