python scatter with histogram

Solutions on MaxInterview for python scatter with histogram by the best coders in the world

showing results for - "python scatter with histogram"
Lucia
06 Jan 2019
1# Create some normally distributed data
2mean = [0, 0]
3cov = [[1, 1], [1, 2]]
4x, y = np.random.multivariate_normal(mean, cov, 3000).T
5
6# Set up the axes with gridspec
7fig = plt.figure(figsize=(6, 6))
8grid = plt.GridSpec(4, 4, hspace=0.2, wspace=0.2)
9main_ax = fig.add_subplot(grid[:-1, 1:])
10y_hist = fig.add_subplot(grid[:-1, 0], xticklabels=[], sharey=main_ax)
11x_hist = fig.add_subplot(grid[-1, 1:], yticklabels=[], sharex=main_ax)
12
13# scatter points on the main axes
14main_ax.plot(x, y, 'ok', markersize=3, alpha=0.2)
15
16# histogram on the attached axes
17x_hist.hist(x, 40, histtype='stepfilled',
18            orientation='vertical', color='gray')
19x_hist.invert_yaxis()
20
21y_hist.hist(y, 40, histtype='stepfilled',
22            orientation='horizontal', color='gray')
23y_hist.invert_xaxis()
24