Skip to content

Instantly share code, notes, and snippets.

View pmarshwx's full-sized avatar

Patrick Marsh pmarshwx

View GitHub Profile
@pmarshwx
pmarshwx / axes_grid1_cbar_bug.py
Created July 16, 2011 16:43
Demonstrates bug in the tick-labels of a colorbar in axes_grid1 ImageGrid
import numpy as np
from matplotlib.pyplot import figure, scatter, colorbar
from matplotlib.colors import ListedColormap, BoundaryNorm
def get_colors():
values = [0., 0.01, 0.1, 0.25, 0.5, 0.75, 1., 1.25, 1.5, 1.75, 2., 2.5, 3.,
4., 5., 6., 7., 8., 9., 10., 11., 12., 13., 14., 15.]
colors = ["#FFFFFF", "#7FFF00", "#00CD00", "#008B00", "#104E8B", "#1E90FF",
"#00B2EE", "#00EEEE", "#8968CD", "#912CEE", "#8B008B", "#8B0000",
@pmarshwx
pmarshwx / find_distance.py
Created October 25, 2011 14:06
Find the shortest geometric distance between four observations and 1148 forecast locations
import numpy as np
def great_circle(lon1, lat1, lon2, lat2):
delta = lon2 - lon1
a = np.radians(lat1)
b = np.radians(lat2)
c = np.radians(delta)
x = np.sin(a) * np.sin(b) + np.cos(a) * np.cos(b) * np.cos(c)
@pmarshwx
pmarshwx / centered_text_issue.py
Created March 9, 2012 03:31
Centered Text Issue
#!/usr/bin/env python
import matplotlib as mpl
import matplotlib.pyplot as plt
from mpl_toolkits.axes_grid1 import axes_divider as divider
from mpl_toolkits.axes_grid1.anchored_artists import AnchoredText
def add_center_text(ax):
pos = ax.get_position().bounds
l, b, w, h = pos
@pmarshwx
pmarshwx / hatch.py
Created April 13, 2012 16:25
Example showing hatching problem with matplotlib
#!/usr/bin/env python
import numpy as np
import matplotlib.pyplot as plt
x = np.random.rand(10) * 10
y = np.random.rand(10) * 10
plt.fill(x, y, fill=False, hatch='/', linestyle='dashed')
plt.savefig('incorrect_example.png')
plt.show()
@pmarshwx
pmarshwx / Traceback
Created July 11, 2012 04:27
A self-contained example script to highlight the quadmesh bug on OSX using MacOSX backend
Commit: 8c57e4fe4909815092af470f4a036c80b407382c
Traceback (most recent call last):
File "/Users/pmarsh/.local/lib/python2.7/site-packages/matplotlib/artist.py", line 55, in draw_wrapper
draw(artist, renderer, *args, **kwargs)
File "/Users/pmarsh/.local/lib/python2.7/site-packages/matplotlib/figure.py", line 927, in draw
func(*args)
File "/Users/pmarsh/.local/lib/python2.7/site-packages/matplotlib/artist.py", line 55, in draw_wrapper
draw(artist, renderer, *args, **kwargs)
@pmarshwx
pmarshwx / latlonkwtext.py
Created August 19, 2012 19:37
Simple script to test the latlon keword argument added to plot
import matplotlib.pyplot as plt
from mpl_toolkits.basemap import Basemap
def draw_map_background(m, ax):
ax.set_axis_bgcolor('#729FCF')
m.fillcontinents(color='#FAFAFA', ax=ax, zorder=0)
m.drawstates(ax=ax)
m.drawcountries(ax=ax)
m.drawcoastlines(ax=ax)
KM = 1000.
clat = 39.3
@pmarshwx
pmarshwx / prospectus.ipynb
Created September 4, 2012 00:36
Explanation of Dissertation Research Using IPython Notebook
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@pmarshwx
pmarshwx / figure_crash.ipynb
Created September 7, 2012 22:27
Crash of IPython Notebook
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@pmarshwx
pmarshwx / rotated_anisotropic_gaussian_kde.pyx
Created October 16, 2012 17:05
Rotated, Anisotropic Gaussian Kernel Density Estimation
cimport cython
import numpy as np
cimport numpy as np
cdef extern from 'math.h':
float exp(float x)
float cos(float x)
float sin(float x)
float fabs(float x)
@pmarshwx
pmarshwx / FFT_smoothing.ipynb
Created October 19, 2012 17:12
Learning how to use FFT to do KDE
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.