How to print x-axes labels in pandas.Series.plot()?

I am trying to visualise my data to understand the data skewness. For that purpose, I use the below and get desired output -

df.groupby('owner_team').inc_subj.count().plot.bar(ylim=0)


Output - My concern is the x-axes labels are shown as numbers, which is the exactly values present. But, my desire is to see the names (string values) corresponding to those numbers.

To give a little bit of background, initially they were string values which I converted to integer values using factorize():

df['owner_team'], mapp = df['owner_team'].factorize()


I am referencing this Pandas doc but couldn't find the exact parameter to set. Tried labels but didn't help.

ps. Using Pandas v0.23.4 and Python v3.6

• Without sample data it is hard to understand where the names are stored. – gented Mar 6 '19 at 12:26

Having a look at the Pandas plot method (on the DataFrame object), we can see that it returns a matplotlib Axes object.

Try something like this:

ax = df.groupby('owner_team').inc_subj.count().plot.bar(ylim=0)

ax.set_xticklabels(df.owner_team)     # if they are still present as strings


If you removed that column, go back to your original processing and keep a copy of it somewhere then use that column above, instead.

Matplotlib will also generally be able to link to the current/latest plot (figure) that has been created. So using the Pandas plot method, you would need to intercept that.You can then try using standard matplotlib methods (e.g. plt.xlabels and so on).

Ther emight be a nice way using the pandas API directly, but I haven't come across that.

• I used ax.set_xticklabels(mapp) and got the labels printed. Thanks. :) – ranit.b Mar 6 '19 at 12:59