2017-10-13 29 views

回答

0

试试这个:

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

fig = plt.figure(figsize=(18,12)) 
ax = fig.add_subplot(111, projection='3d') 

x_data, y_data = np.meshgrid(np.arange(5),np.arange(3)) 
z_data = np.random.rand(3,5) 
colors = ['r','g','b'] # colors for every line of y 

# plot colored 3d bars 
for i in xrange(3): # cycle though y 
    # I multiply one color by len of x (it is 5) to set one color for y line 
    ax.bar3d(x_data[i], y_data[i], z_data[i], 1, 1, z_data[i], alpha=0.1, color=colors[i]*5) 
    # or use random colors 
    # ax.bar3d(x_data[i], y_data[i], z_data[i], 1, 1, z_data[i], alpha=0.1, color=[np.random.rand(3,1),]*5) 
plt.show() 

结果: enter image description here

+0

这已经提出了一个建议,但这不是我所期待的。我想要生成像这样的https://i.stack.imgur.com/DOz6r.png。 – user2820579

+0

你在代码中使用ax.bar3d函数吗? – yatinsingla

+0

这可以帮助你。 https://stackoverflow.com/questions/43869751/change-bar-color-in-a-3d-bar-plot-in-matplotlib-based-on-value – yatinsingla

相关问题