Skip to content Skip to sidebar Skip to footer

Plot With Pandas, Xticks

I have some pandas DataFrame with the next structure: A B C 0 1 1 1 1 1 2 2 2 1 3 3 . . . . Now, after sort operation, I want to plot for example column B. I use next command in

Solution 1:

plot() passes over all (additional) parameter you give to it to the original plt.plot().

Removed

df = pd.DataFrame([[1, 1, 1],[1, 2, 2], [1, 3, 3]], columns=['A', 'B', 'C'])
df['B'].plot(kind='bar')

These commands return exactly what I expected. The values of 'B' are the bars, and the x-values are the indices of the DataFrame. After looking it up in the manual, I found that what I wrongly advertised as left is actually the data. In order to label it, you have to do the following (or similar):

ax = df['B'].plot(kind='bar')
ax.set_xticklabels(list(df['C']))

Post a Comment for "Plot With Pandas, Xticks"