Home > Net >  How do you get dates on the start on the specified month? (matplotlib)
How do you get dates on the start on the specified month? (matplotlib)

Time:01-21

# FEB
# configuring the figure and plot space
fig, lx = plt.subplots(figsize=(30,10))

# converting the Series into str so the data can be plotted
wd = df2['Unnamed: 1']
wd = wd.astype(float)

# adding the x and y axes' values
lx.plot(list(df2.index.values), wd)

# defining what the labels will be 
lx.set(xlabel='Day', ylabel='Weight', title='Daily Weight February 2022')

# defining the date format 
date_format = DateFormatter('%m-%d')
lx.xaxis.set_major_formatter(date_format)
lx.xaxis.set_minor_locator(mdates.WeekdayLocator(interval=1))

Values I would like the x-axis to have:

['2/4', '2/5', '2/6', '2/7', '2/8', '2/9', '2/10', '2/11', '2/12', '2/13', '2/14', '2/15', '2/16', '2/17', '2/18', '2/19', '2/20', '2/21', '2/22', '2/23', '2/24', '2/25', '2/26', '2/27']

Values on the x-axis:

enter image description here

  • Related