How to order the tick labels on a discrete axis (0 indexed like a bar plot)

I have a dataframe with this data and want to plot it with a bar graph with x-axis labels being months

import pandas as pd

data = {'Birthday': ['1900-01-31', '1900-02-28', '1900-03-31', '1900-04-30', '1900-05-31', '1900-06-30', '1900-07-31', '1900-08-31', '1900-09-30', '1900-10-31', '1900-11-30', '1900-12-31'],
        'Players': [32, 25, 27, 19, 27, 18, 18, 21, 23, 21, 26, 23]}
df = pd.DataFrame(data)

  Birthday Players
1900-01-31      32
1900-02-28      25
1900-03-31      27
1900-04-30      19
1900-05-31      27
1900-06-30      18
1900-07-31      18
1900-08-31      21
1900-09-30      23
1900-10-31      21
1900-11-30      26
1900-12-31      23

This is what I have

import pandas as pd
import matplotlib.pyplot as plt
import matplotlib.dates as mdates

fig = plt.figure(figsize=(12, 7))
locator = mdates.MonthLocator()
fmt = mdates.DateFormatter('%b')
X = plt.gca().xaxis
X.set_major_locator(locator)
X.set_major_formatter(fmt)
plt.bar(month_df.index, month_df.Players, color = 'maroon', width=10)

but the result is this with the label starting from Feb instead of Jan

enter image description here



from Recent Questions - Stack Overflow https://ift.tt/32JcZAp
https://ift.tt/311btZT

Comments

Popular posts from this blog

Today Walkin 14th-Sept

Spring Elasticsearch Operations

Hibernate Search - Elasticsearch with JSON manipulation