URFMODEG
URFMODEG

Reputation: 37

Matplotlib with pandas pivot table lables

I cannot get the right labels for x, it keeps making them ints instead of the right value.

Here is my code:

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)

Upvotes: 0

Views: 486

Answers (1)

ImportanceOfBeingErnest
ImportanceOfBeingErnest

Reputation: 339102

Because you explicitely set the xlabel to num, ax.set_xlabel(num), you get integers as xlabel. If you want something else as xlabel, you need to specify it in the call to ax.set_xlabel(something_else).

Upvotes: 1

Related Questions