Last active
May 18, 2017 15:44
-
-
Save mattpitkin/7f270853f1a70143e48b1c6c016ae23b to your computer and use it in GitHub Desktop.
Example for producing a contour plot and also plotting the points outside the outer contour
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
from matplotlib import pyplot as pl | |
x = np.random.randn(5000) | |
y = 0.2*np.random.randn(5000) + 3 | |
xbins = 20 | |
ybins = 20 | |
H, xedges, yedges = np.histogram2d(x, y, bins=(xbins, ybins)) | |
# set levels as in IDL djs_contourpts https://searchcode.com/codesearch/view/84370/ | |
nlevels = 3 | |
levels = ((np.arange(nlevels)+1) * np.max(H[:])) / float(nlevels) | |
C = pl.contour(H.T, extent=[xedges[0], xedges[-1], yedges[0], yedges[-1]], levels=levels) | |
p = C.collections[0].get_paths()[0] | |
poutside = ~p.contains_points(np.vstack((x,y)).T) | |
pl.plot(x[poutside], y[poutside], '.') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This example stems from this facebook post.
Following another comment on that post my example seems to be similar to what is done in the astroML
scatter_contour
function