1
在這個問題被質疑How do I keep the smaller value in a bar chart in front (when I cannot place the bars side by side)?如何保持在前面較小值的3D條形圖
我想要做這樣的事情在3D繪圖相關。儘管掩碼看起來不錯,但情節只顯示更高的值。我無法理解爲什麼這段代碼不會繪製不會覆蓋對方的酒吧。每個步驟(ax.bar)看起來都不錯,但是結合在一起只顯示更高的值。我究竟做錯了什麼?
from mpl_toolkits.mplot3d import Axes3D
import matplotlib.pyplot as plt
import numpy as np
import numpy.ma as ma
dim1 = np.array([0, 1, 0, 1])
dim2 = np.array([0, 0, 1, 1])
var1 = np.array([1, 2, 1.5, 1.25])
var2 = np.array([0.5, 2.2, 1.15, 1.75])
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
mask_var1 = ma.where(var1>=var2)
mask_var2 = ma.where(var2>=var1)
print mask_var1
print mask_var2
# Draw var1 bar where var1 >= var2
ax.bar(dim1[mask_var1], var1[mask_var1], dim2[mask_var1], zdir='y', width=0.1, color='red')
# Draw var2
ax.bar(dim1, var2, dim2, zdir='y', width=0.1, color='blue')
# Draw var1 bar where var2 >= var1
ax.bar(dim1[mask_var2], var1[mask_var2], dim2[mask_var2], zdir='y', width=0.1, color='red')
plt.show()