In [1]:
%matplotlib inline
In [2]:
import numpy as np
import matplotlib.pyplot as plt
import h5py
In [3]:
f = h5py.File("data-readonly/histogram_data.h5")
In [4]:
list(f.keys())
Out[4]:
In [5]:
dist = f["dist"].value
In [6]:
dist
Out[6]:
In [7]:
dist.shape
Out[7]:
In [8]:
plt.scatter(dist[:,0], dist[:,1])
Out[8]:
In [9]:
plt.hist(dist[:,0])
Out[9]:
In [10]:
plt.hist(dist[:,1])
Out[10]:
In [11]:
plt.hexbin(dist[:,0], dist[:,1], gridsize=32)
plt.colorbar();
In [12]:
weights_x = f["weights_x"].value
weights_y = f["weights_y"].value
weights_xy_x = f["weights_xy_x"].value
weights_xy_y = f["weights_xy_y"].value
weights_xy_normal = f["weights_xy_normal"].value
In [13]:
weights_x.shape
Out[13]:
In [14]:
plt.hist(dist[:,0], weights=weights_x)
Out[14]:
In [15]:
plt.hexbin(dist[:,0], dist[:,1], weights_xy_x, gridsize=32)
Out[15]:
In [16]:
plt.hist(dist[:,0], weights=weights_xy_x, bins=32);
In [17]:
import ipywidgets
In [18]:
def plot_hexbin(gridsize, weight_by):
if weight_by == "none":
weights = None
elif weight_by == "x":
weights = weights_xy_x
elif weight_by == "y":
weights = weights_xy_y
elif weight_by == "normal":
weights = weights_xy_normal
else:
raise RuntimeError
plt.hexbin(dist[:,0], dist[:,1], weights, gridsize=gridsize)
In [19]:
ipywidgets.interact(plot_hexbin,
gridsize = (2, 128, 1),
weight_by = ["none", "x", "y", "normal"])
Out[19]:
In [20]:
plot_hexbin(64, weight_by = "none")
In [21]:
plot_hexbin(64, weight_by = "x")
In [22]:
plot_hexbin(64, weight_by = "y")
In [23]:
plot_hexbin(64, weight_by = "normal")
In [24]:
dist2 = np.random.normal(0.5, 0.1, size=dist.shape)
In [25]:
plt.hexbin(dist2[:,0], dist2[:,1])
Out[25]:
In [26]:
plt.hist(dist2[:,0], weights=dist2[:,1]);
In [27]:
plt.hexbin(dist2[:,0], dist2[:,1], gridsize=32)
plt.colorbar();
In [29]:
dist3 = np.random.triangular(0.0, 0.25, 1.0, size=dist2.shape)
In [30]:
plt.hexbin(dist3[:,0], dist3[:,1], gridsize=32)
Out[30]:
In [31]:
plt.hist(dist3[:,0], bins=32);
In [32]:
dist3 = np.random.triangular(0.0, 0.25, 1.0, size=dist2.shape)
fig = plt.figure(figsize=(8,8))
hexbin_axes = fig.add_axes([0.0, 0.0, 0.9, 0.9])
hexbin_axes.hexbin(dist2[:,0], dist3[:,1], gridsize=32)
histx_axes = fig.add_axes([0.0, 0.9, 0.9, 0.1])
histx_axes.hist(dist2[:,0], bins=32)
histy_axes = fig.add_axes([0.9, 0.0, 0.1, 0.9])
histy_axes.hist(dist3[:,1], bins=32, orientation='horizontal')
histx_axes.xaxis.set_visible(False)
histx_axes.yaxis.set_visible(False)
histx_axes.set_frame_on(False)
histy_axes.xaxis.set_visible(False)
histy_axes.yaxis.set_visible(False)
histy_axes.set_frame_on(False)
;
Out[32]:
In [33]:
plt.hist(dist2[:,0], bins=32, normed=True);
In [34]:
plt.hist(dist2[:,0], bins=32, normed=False);
In [35]:
dist3 = np.random.triangular(0.0, 0.25, 1.0, size=dist2.shape)
fig = plt.figure(figsize=(8,8))
hexbin_axes = fig.add_axes([0.0, 0.0, 0.9, 0.9])
hb = hexbin_axes.hexbin(dist2[:,0], dist3[:,1], gridsize=32, extent = [0.0, 1.0, 0.0, 1.0])
vals, bins = np.histogram(dist2[:,0], range = [0.0, 1.0], bins = 32, normed=True)
vals.shape = (1, vals.shape[0])
histx_axes = fig.add_axes([0.0, 0.9, 0.9, 0.1], sharex = hexbin_axes)
imx = histx_axes.imshow(vals, origin='lower', extent=[0.0, 1.0, 0.0, 1.0])
histx_axes.xaxis.set_visible(False)
histx_axes.yaxis.set_visible(False)
vals, bins = np.histogram(dist3[:,1], range = [0.0, 1.0], bins = 32, normed=True)
vals.shape = (vals.shape[0], 1)
histy_axes = fig.add_axes([0.9, 0.0, 0.1, 0.9], sharey = hexbin_axes)
imy = histy_axes.imshow(vals, origin='lower', extent=[0.0, 1.0, 0.0, 1.0]);
histy_axes.xaxis.set_visible(False)
histy_axes.yaxis.set_visible(False)
In [ ]: