0
$\begingroup$

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 - enter image description here 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.

Any pointers please.

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

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

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.

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.