我无法获得x的正确标签,它会使它们保持整数而不是正确的值。
这是我的代码:
def animate(num, f, a, canvas):
global index
data = pd.read_csv("train.csv")
table = pd.pivot_table(data=data, values=index, index=num, columns='Survived', aggfunc='count')
a.clear()
bar_1 = table[0]
# Array with the survivors, divided between male and female
bar_2 = table[1]
# Range com a quantidade de itens das barras
x_pos = np.arange(len(bar_1))
a.set_xlabel(num)
a.set_ylabel("Survived")
a.bar(x_pos, bar_1, 0.5, color='b')
a.bar(x_pos, bar_2, 0.5, color='y', bottom=bar_1)
# Definir position and labels for the X axis
plt.xticks(x_pos+0.25, ('Female','Male'))
canvas.draw()
canvas.get_tk_widget().pack(side=tk.TOP, fill=tk.BOTH, expand=True)
答案 0 :(得分:1)
因为您明确地将xlabel设置为num
,ax.set_xlabel(num)
,所以您将整数设为xlabel。如果你想要其他东西作为xlabel,你需要在调用ax.set_xlabel(something_else)
。