2D and 3D Scatter Histograms from arrays in Python

匿名 (未验证) 提交于 2019-12-03 02:26:02

问题:

have you any idea, how I can bin 3 arrays to a histogram. My arrays look like

Temperature = [4,   3,   1,   4,   6,   7,   8,   3,   1] Radius      = [0,   2,   3,   4,   0,   1,   2,  10,   7] Density     = [1,  10,   2,  24,   7,  10,  21, 102, 203]

And the 1D plot should look:

Density       |           X 10^2-|               X      |       X 10^1-|         |   X 10^0-|      |___|___|___|___|___   Radius          0  3.3 6.6  10

And the 2D plot should (qualitative) look like:

Density       |           2      | | 10^2-|      11249       | |      |     233          | | Radius 10^1-|    12            | |      |   1              | | 10^0-|      |___|___|___|___|___   Temperature          0   3   5   8

So I want to bin one or two fields with python/numpy and then plot them to analyse their correspondence.

回答1:

Here it follows two functions: hist2d_bubble and hist3d_bubble; that may fit for your purpose:

import numpy as np import matplotlib.pyplot as pyplot from mpl_toolkits.mplot3d import Axes3D   def hist2d_bubble(x_data, y_data, bins=10):     ax = np.histogram2d(x_data, y_data, bins=bins)     xs = ax[1]     ys = ax[2]     points = []     for (i, j), v in np.ndenumerate(ax[0]):         points.append((xs[i], ys[j], v))      points = np.array(points)     fig = pyplot.figure()     sub = pyplot.scatter(points[:, 0],points[:, 1],                          color='black', marker='o', s=128*points[:, 2])     sub.axes.set_xticks(xs)     sub.axes.set_yticks(ys)     pyplot.ion()     pyplot.grid()     pyplot.show()     return points, sub   def hist3d_bubble(x_data, y_data, z_data, bins=10):     ax1 = np.histogram2d(x_data, y_data, bins=bins)     ax2 = np.histogram2d(x_data, z_data, bins=bins)     ax3 = np
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!