Skip to content

Instantly share code, notes, and snippets.

import json
from datetime import datetime
import time
def parse_date(date):
return datetime.strptime(date, "%Y-%m-%d").date()
count = 0
leg_count = 0
old_ends = []
Sherrod Brown
term N end 1996-10-04
term N+1 start 1997-01-07
gap % 365: 95
Benjamin L. Cardin
term N end 1988-10-22
term N+1 start 1989-01-03
gap % 365: 73
####################################
# diamond data bar chart
# Questions? Email feedback@plot.ly
# For more docs, see plot.ly/api
####################################
library(plotly)
py <- plotly(username='USERNAME', key='API_KEY')
####################################
# diamond data bar chart
# Questions? Email feedback@plot.ly
# For more docs, see plot.ly/api
####################################
library(plotly)
py <- plotly(username='USERNAME', key='API_KEY')
@bchartoff
bchartoff / oldfaithful
Created December 10, 2013 22:21
Code to create multi axis plots in Plotly
#combine elements with same name in two named lists (useful for combining layouts)
appendList <- function (x, val)
{
stopifnot(is.list(x), is.list(val))
xnames <- names(x)
for (v in names(val)) {
x[[v]] <- if (v %in% xnames && is.list(x[[v]]) && is.list(val[[v]]))
appendList(x[[v]], val[[v]])
else c(x[[v]], val[[v]])
}
@bchartoff
bchartoff / oldfaithfuldoublehist
Created December 11, 2013 01:54
Old faithful data with histograms on both axes in plotly
#combine elements with same name in two named lists (useful for combining layouts)
appendList <- function (x, val)
{
stopifnot(is.list(x), is.list(val))
xnames <- names(x)
for (v in names(val)) {
x[[v]] <- if (v %in% xnames && is.list(x[[v]]) && is.list(val[[v]]))
appendList(x[[v]], val[[v]])
else c(x[[v]], val[[v]])
}
@bchartoff
bchartoff / Sports_heatmaps
Created December 19, 2013 17:30
SDQL and plotly API scripts to generate sports score heatmaps.
import urllib, urlparse
import re
import random
import numpy
API_KEY = "SDQL_KEY"
# I want to jiggle Y and Yo?
def jiggler(lst,jiggle):
return [x + jiggle * ( random.random() - 0.6 ) for x in lst]
import urllib, urlparse
import re
import random
import numpy
API_KEY = "SDQL_KEY"
# I want to jiggle Y and Yo?
def jiggler(lst,jiggle):
return [x + jiggle * ( random.random() - 0.6 ) for x in lst]
from rpy2 import robjects
r = robjects.r
r.library("ggplot2")
robjects.r("p = ggplot(aes(price, carat), data=diamonds) + geom_point() + facet_grid(clarity ~ color, scales = 'free')")
r.ggsave('faceted_plot.jpeg')
robjects.r('print(p)')
r['dev.off']()
@bchartoff
bchartoff / gist:bdd2a96a0c3b72b2942c
Created May 27, 2014 20:17
Molten Chocolate Cake
MAKES 6 INDIVIDUAL CAKES
5 1/2 ounces imported bittersweet (not unsweetened) chocolate
such as Caillbotte or Valrhona
11 Tablespoons unsalted butter
3 large eggs
3 egg yolks
1/4 cup plus 2 Tablespoons sugar