Python 带数据透视表标签的Matplotlib

Python 带数据透视表标签的Matplotlib,python,pandas,matplotlib,Python,Pandas,Matplotlib,我无法为x获得正确的标签,它一直使它们成为int而不是正确的值 这是我的密码: 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_

我无法为x获得正确的标签,它一直使它们成为int而不是正确的值

这是我的密码:

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)

因为您明确地将xlabel设置为num,ax.setxlabelnum,所以可以将整数设置为xlabel。如果您希望将其他内容作为xlabel,则需要在对ax.set\u xlabelsomething\u else的调用中指定它。

问题不清楚且不可重现。请阅读并了解如何创建一个。那你的问题呢。