1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
| import numpy as np import matplotlib.pyplot as plt from mpl_toolkits.axes_grid1 import make_axes_locatable
np.random.seed(19680801)
x = np.random.randn(1000) y = np.random.randn(1000)
fig, axScatter = plt.subplots(figsize=(5.5, 5.5))
axScatter.scatter(x, y) axScatter.set_aspect(1.)
divider = make_axes_locatable(axScatter) axHistx = divider.append_axes("top", 1.2, pad=0.1, sharex=axScatter) axHisty = divider.append_axes("right", 1.2, pad=0.1, sharey=axScatter)
axHistx.xaxis.set_tick_params(labelbottom=False) axHisty.yaxis.set_tick_params(labelleft=False)
binwidth = 0.25 xymax = max(np.max(np.abs(x)), np.max(np.abs(y))) lim = (int(xymax/binwidth) + 1)*binwidth
bins = np.arange(-lim, lim + binwidth, binwidth) axHistx.hist(x, bins=bins) axHisty.hist(y, bins=bins, orientation='horizontal')
axHistx.set_yticks([0, 50, 100])
axHisty.set_xticks([0, 50, 100])
plt.show()
|