Created
March 23, 2021 15:17
-
-
Save lzkelley/a8e8d019fa5c8d148c8104ffb2a04662 to your computer and use it in GitHub Desktop.
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 | |
import scipy as sp | |
import scipy.stats | |
import matplotlib as mpl | |
import matplotlib.pyplot as plt | |
size = 1e4 | |
aa = 10**np.random.normal(-2.0, size=int(size)) | |
aa = np.clip(aa, 1e-5, 1.0) | |
bb = 10**np.random.uniform(-4, 0, size=aa.size) | |
def logspace(vals, size): | |
extr = [vals.min(), vals.max()] | |
return np.logspace(*np.log10(extr), size) | |
xedges = logspace(aa, 20) | |
yedges = logspace(bb, 25) | |
hist, *_ = sp.stats.binned_statistic_2d(aa, bb, None, bins=(xedges, yedges), statistic='count') | |
norm = mpl.colors.LogNorm(vmin=hist[hist>0].min(), vmax=hist.max()) | |
ax = plt.gca() | |
ax.set(xscale='log', yscale='log') | |
xx, yy = np.meshgrid(xedges, yedges) | |
pcm = ax.pcolormesh(xedges, yedges, hist.T, cmap='viridis', norm=norm) | |
ax.scatter(aa, bb, s=2, alpha=0.1, color='r') | |
plt.colorbar(pcm, ax=ax, label='number') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment