0

I am new at Data Visualization with Python. I want to be able to plot the Groupby() results in a bar chart. I have converted a categorical array using the pd.factorize() function in Python. Then, I created a plot using the results of the groupby function.

Here is my code:

fact=pd.factorize(data['DayOfWeek'])

data['fact'].groupby(data['fact_dow']).count().plot(kind='bar',figsize=(14,8))

plt.show()

The resulting image is: enter image description here

It looks almost good but the x-labels are the factorized results, I need to map them to their corresponding values.

Any one knows how to do this in a pythonic way? Also, if there are other suggestions as to how to do it, please comment.

Anantha Raju C
  • 1,780
  • 12
  • 25
  • 35
Max Payne
  • 387
  • 3
  • 17

1 Answers1

0

If the data['DayOfWeek'] corresponds to the labels, then use plt.xticks(data['DayOfWeek'])

Kennet Celeste
  • 4,593
  • 3
  • 25
  • 34
  • Thanks, the `xticks` change the values, however, how can I use String values in the Ticker? The ticker labels are held in the `fact[1]` array not in the `data` array – Max Payne Oct 24 '16 at 00:53
  • @JuanDaza It's still unclear to me. You are saying "how can I use String values in the Ticker?". what does that mean? how are you going to use it ? are you going to use it for something other than setting the x-ticks? – Kennet Celeste Oct 24 '16 at 05:10
  • I figured it out, I am sorry if I was unclear. I wanted to add custom values to the x-ticker. These were not numerical values. I found it here [link](http://http://stackoverflow.com/questions/3100985/plot-with-custom-text-for-x-axis-points) – Max Payne Oct 27 '16 at 08:51