I would like to replace some xticks with self-label ticks, my codes is the following:
from mpl_toolkits.mplot3d import Axes3D  
import matplotlib.pyplot as plt  
from matplotlib import cm  
from matplotlib.ticker import LinearLocator  
import numpy as np  
import matplotlib.colors  
fig = plt.figure()  
ax = fig.gca(projection='3d')  
X = np.arange(3)  
Z = np.arange(4)  
X, Z = np.meshgrid(X, Z)  
V1 = np.array([[0.5,0.5],[0,0.9],[0,0.9]])  
V2 = np.array([[0,0.5],[0,0.5],[0,0.5]])  
V3 = np.array([[0,0.5],[0,0.5],[0,0.5]])  
V_list = [V1,V2,V3]  
norm = matplotlib.colors.Normalize(vmin=0, vmax=1)  
for i in range(3):  
    ax.plot_surface(X, np.ones(shape=X.shape)+i, Z, facecolors=plt.cm.ocean(norm(V_list[i])), linewidth=0, edgecolor="black")  
x_ticks = [(X[i] + X[i+1])/2 for i in range(len(X)-1)]  
ax.set_xticks(x_ticks)  
ax.set_xticklabels(['a','b'])  
ax.set_xlabel('x')  
m = cm.ScalarMappable(cmap=plt.cm.ocean, norm=norm)  
m.set_array([])  
plt.colorbar(m)  
plt.show()  
These codes end up with ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all() However, if I change
x_ticks = [(X[i] + X[i+1])/2 for i in range(len(X)-1)]  
ax.set_xticks(x_ticks)  
ax.set_xticklabels(['a','b'])  
to
ax.set_xticks([0.5,1.5])  
ax.set_xticklabels(['a','b'])
then, the codes work. I was wondering why this happened since [(X[i] + X[i+1])/2 for i in range(len(X)-1)] is the same list as [0.5,1.5] and how can I use [(X[i] + X[i+1])/2 for i in range(len(X)-1)] for set_xticks. Thanks in advance!
Kun
