# Datetime x axis for months

**URL:** <https://community.plotly.com/t/datetime-x-axis-for-months/41776>\
**Category:** 📊 Plotly Python\
**Created:** [June 30, 2020, 9:33am UTC](https://community.plotly.com/t/datetime-x-axis-for-months/41776 "2020-06-30T09:33:18Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![scott39](https://avatars.discourse-cdn.com/v4/letter/s/51bf81/32.png) [@scott39](https://community.plotly.com/u/scott39)\
**Post date:** [June 30, 2020, 9:33am UTC](https://community.plotly.com/t/datetime-x-axis-for-months/41776/1 "2020-06-30T09:33:18Z")

</div>

I am trying to plot a few variables with x-axis datetime ranging over several years. I want my final result to have the x-axis range from Jan to Dec and showing different colored lines for each year and value.  
Similar to this:  
 ![image](https://us1.discourse-cdn.com/flex024/uploads/plot/original/2X/d/dae77a664f383bffe958ae1bacee8422190241d4.png)

I convert my “Date” column to datetime, and can also extract the year portion.

> df[‘Date’]=pd.to\_datetime(df[‘Date’],errors=‘coerce’)  
> df[‘year’]=df[‘Date’].dt.year  
> df[‘mthday’]=df[‘Date’].dt.strftime(‘%d-%b’)  
> df=df.sort\_values(by=‘Date’)  
> plot=px.line(df,x=‘Date’,y=‘Systolic ‘,color=‘year’)  
> plot.update\_layout(xaxis\_tickformat=’%d-%b’)

With this, the different years are correctly shown in different colors, and the x-axis labels are correctly showing day and month, but the x-axis spans several years. I want it to only show Jan to Dec. (i.e: collapse the graphs in the picture below w the x-axis showing only one set of twelve months)

 ![Capture](https://us1.discourse-cdn.com/flex024/uploads/plot/original/2X/8/8404d09cfb63fecaa2248248e2d355c27ec5881a.png)

I have also tried to change the x to df[‘mthday’] but then the graphs become jumbled up. (I think it’s because the strftime for mthday makes the value in that column not a datetime???)

How do I plot with different years and x-axis only showing Jan to Dec?
