#encoding=utf-8 from mpl_toolkits.mplot3d import Axes3D import matplotlib.pyplot as plt import numpy as np import random fig = plt.figure() ax = fig.add_subplot(111, projection='3d') #x = [-5,-4,-3,-3,-3,-3,3,4,2,2,2,2,2,1,1,1,1,1,0,0,0,0,0,-1,-1,-1,-1,-1,-1,-2,-2,-2,-2,-2] #x coordinates of each bar y = [6,4,7,6,5,4,5,6,3,4,5,6,7,3,4,5,6,7,6,5,4,3,2,7,6,5,4,3,2,7,6,5,4,3] #y coordinates of each bar #z = [0,0,1,0,0,0,0.5,1,0,0,0,1,1,0,0,0.142,0.167,1,0.76,0,0,0,0,1,0.909,0,0,0,0,1,0.67,0,0,0] #z coordinates of each bar dx = [1, 1, 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1] #width of each bar dy = [1, 1, 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1] #depth of each bar #dz = [0.1,0.1,0.1,0.1,0.1,0.1,0.1,0.1,0.1,0.1,0.1,0.1,0.1,0.1,0.1,0.1,0.1,0.1,0.1,0.1,0.1,0.1,0.1,0.1,0.1,0.1,0.1,0.1,0.1,0.1,0.1,0.1,0.1,0.1] #height of each bar dp=[0,0,1,0,0,0,0.5,1,0,0,0,1,1,0,0,0.142,0.167,1,0.76,0,0,0,0,1,0.909,0,0,0,0,1,0.67,0,0,0] #x1=np.array(x) #y1=np.array(y) #z1=np.array(z) #ax.plot_surface(x, y, z, color='b') x=[-5,-4,-4,-4,-4,-3,-3,-3,-3,-3,-2,-2,-2,-2,-2,-1,-1,-1,-1,-1,-1,0,0,0,0,0,0,0,1,1,1,1,1,1,2,2,2,2,2,2,3,3,3,4,4,4,5,6,7,8] y=[4,3,4,5,6,3,4,5,6,7,3,4,5,6,7,2,3,4,5,6,7,2,3,4,5,6,7,8,1,3,4,5,6,7,2,3,4,5,6,7,3,5,7,4,6,5,5,6,7,8] dz=[0,0,0,25,0,0,50,0,50,100,0,0,0,68.42105263,100,0,0,6.25,30,91.42857143,100,0,0,6.666666667,16.66666667,82.85714286,100,100,0,0,0,9.090909091,52.38095238,100,2.631578947,0,0,28.57142857 ,100,100,3.015075377,50,100,4.961832061,100,66.66666667,20.59308072,77.13097713,99.03381643,100] bottom=np.zeros_like(x) #color=plt.cm.Set2(random.choice(range(8)))#random.choice()从里面随机选出一个值,这样每次画的图形颜色就不一样了。 #ax.bar(xs,ys,zs=z,zdir='y',color=color,alpha=0.8) for i in range(len(x)): color = plt.cm.Set2(random.choice(range(2))) # random.choice()从里面随机选出一个值,这样每次画的图形颜色就不一样了。 #ax.bar(xs, ys, zs=z, zdir='y', color=color, alpha=0.8) ax.bar3d(x[i], y[i], bottom[i], dx[i], dy[i], dz[i], color=color, zsort='average', alpha=0.8) ax.set_xlabel('DIF') ax.set_ylabel('AVG') ax.set_zlabel('Pro') plt.show()
画三维直方图
最新推荐文章于 2024-06-17 09:51:54 发布