Skip to content

Instantly share code, notes, and snippets.

View bagrow's full-sized avatar

Jim Bagrow bagrow

View GitHub Profile
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# letter_subplots.py
# Jim Bagrow
# Last Modified: 2021-05-07
import numpy as np
import matplotlib.pyplot as plt
@bagrow
bagrow / method_chaining.py
Last active August 3, 2023 16:21
A small example of method chaining/cascading in Python
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# method_chaining.py
# Jim Bagrow
# Last Modified: 2016-12-05
"""
Method chaining (or cascading) is a technique for making many calls to an
object with less code. Each method should return a reference to the object
@bagrow
bagrow / vimtex_workflow.txt
Created February 10, 2011 10:04
Some details for my macvim/skim/latexmk workflow
MacVim + latexmk + Skim workflow:
MacVim http://code.google.com/p/macvim/
Latexmk http://www.phys.psu.edu/~collins/software/latexmk-jcc/
Skim.app http://skim-app.sourceforge.net/
Open the texfile in macvim:
$ mvim <file>.tex
Watch tex file with latexmk (see also ~/.dotfiles/latexmkrc):
$ latexmk -pdf -pvc <file>.tex
<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/rss1full.xsl"?>
<?xml-stylesheet type="text/css" media="screen" href="http://feeds.nature.com/~d/styles/itemcontent.css"?>
<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:prism="http://prismstandard.org/namespaces/basic/2.0/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns="http://purl.org/rss/1.0/" xmlns:admin="http://webns.net/mvcb/" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0">
<channel rdf:about="http://feeds.nature.com/nature/rss/current">
<title>Nature - Issue - nature.com science feeds</title>
<description>Nature is the international weekly journal of science: a magazine style journal that publishes full-length research papers in all disciplines of science, as well as News and Views, reviews, news, features, commentaries, web focuses and more, covering all branches of science and how science i
@bagrow
bagrow / extract_backbone.py
Created April 22, 2014 14:33
Extract the multiscale backbone of a weighted complex network
#!/usr/bin/env python
# extract_backbone.py
# Jim Bagrow
# Last Modified: 2010-11-18
import sys, os
import networkx as nx
@bagrow
bagrow / jet_colors.gnu
Created February 1, 2011 00:12
Love or hate the matlab jet colormap? Want it in gnuplot? Here's how to do it!
set palette defined (0 0.0 0.0 0.5, \
1 0.0 0.0 1.0, \
2 0.0 0.5 1.0, \
3 0.0 1.0 1.0, \
4 0.5 1.0 0.5, \
5 1.0 1.0 0.0, \
6 1.0 0.5 0.0, \
7 1.0 0.0 0.0, \
8 0.5 0.0 0.0 )
@bagrow
bagrow / annotate_with_graphlayout.py
Created December 10, 2015 13:42
Improve the placement of labels on a busy scatterplot
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# annotate_with_graphlayout.py
# Jim Bagrow
# Last Modified: 2015-12-09
"""
Rough improvement of scatter point label placement using
force-directed graph layout.
#!/usr/bin/env python
# color_stuff.py
# Jim Bagrow
# Last Modified: 2016-12-01
import colorsys
def distinguishable_colors(num, sat=1.0, val=1.0):
"""Generate a list of `num' rgb hexadecimal color strings. The strings are
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# exhaustive_search_linearRegression.py
# Jim Bagrow
# Last Modified: 2015-10-05
import sys, os
import numpy as np
import scipy, scipy.stats
@bagrow
bagrow / weighted_choice.py
Created November 7, 2012 00:23
Sample non-uniformly from a set of choices
#!/usr/bin/env python
# weighted_choice.py
# Jim Bagrow
# Last Modified: 2012-11-06
import random, bisect
import pylab
def weighted_choice(choices, num_draws=1):