Plug4
Plug4

Reputation: 3928

Python: Pandas plot histogram with centered x-values

I want to plot the distribution of the following dataset (column maxnet).

If I do the following in Python using Pandas DataFrame:

df['maxnet'].hist(bins=10,range=(5,11), grid=False, alpha=0.3, histtype="stepfilled")

I get the following figure:

enter image description here

As you can see, I don't have the x-axis values centered under each bar. I want the x-values (6, 7, 8, 9, 10) to be centered under the bar. How can I do that?

Also, if I want to change the x-axis label for (Dec6, Dec7, Dec8, Dec9, Dec10), still centered under each bar, how can I do that?

Upvotes: 1

Views: 2455

Answers (1)

Plug4
Plug4

Reputation: 3928

From the suggestion of BrenBarn, I was able solve my problem. Here's my solution:

bar = pd.DataFrame(maxdf['maxnet'].value_counts()) bar = bar.sort() bar.plot(kind='bar')

Upvotes: 3

Related Questions