2012-01-17 41 views
1

下面是示例代码剧情3D直方图与不均匀的长度数组

import numpy as np 
import random 
from matplotlib import pyplot 
from mpl_toolkits.mplot3d import Axes3D 

a = floor(100*random(100)) # create 100 random point 
b = floor(100*random(75)) 
c = floor(100*random(68)) 
    : 
    : 
n = floor(100*random(45)) 

data = [a, b, c, ..., n] 

现在,我想上绘制数据的3D直方图,同时使

x-axis : value 
y-axis : count w.r.t. to the value 
z-axis : ith row of data metrix 

它要么显示栏或3D表面。您的建议将得到肯定。

+0

http://acronyms.thefreedictionary.com/WRT – joaquin 2012-01-17 21:37:13

回答

2

也许使用ax.bar3d

import numpy as np 
import matplotlib.pyplot as plt 
import mpl_toolkits.mplot3d.axes3d as axes3d 
import matplotlib.cm as cm 

np.random.seed(3) 

a = np.random.random_integers(100, size = (100,)) 
b = np.random.random_integers(100, size = (75,)) 
c = np.random.random_integers(100, size = (68,)) 
n = np.random.random_integers(100, size = (45,)) 
data = (a,b,c,n) 
# data = np.random.random_integers(100, size = (4, 100)) # also possible 
fig = plt.figure() 
ax = fig.add_subplot(1, 1, 1, projection = '3d') 

for i, arr in enumerate(data): 
    hist, bin_edges = np.histogram(arr, bins = 10) 
    x = bin_edges[:-1] 
    y = i*np.ones_like(hist) 
    z = np.zeros_like(hist) 
    dx = np.diff(bin_edges) 
    dy = 0.01 
    dz = hist 
    color = cm.RdBu(float(i)/len(data)) 
    ax.bar3d(x, y, z, dx, dy, dz, color = color, alpha = 0.5) 

plt.show() 

enter image description here

+0

非常感谢您的代码。 – 2012-01-18 08:04:13