# Weeks on an x-axes?

**URL:** <https://community.plotly.com/t/weeks-on-an-x-axes/92856>\
**Category:** 📊 Plotly Python\
**Created:** [June 25, 2025, 6:37pm UTC](https://community.plotly.com/t/weeks-on-an-x-axes/92856 "2025-06-25T18:37:12Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![marvy](https://avatars.discourse-cdn.com/v4/letter/m/96bed5/32.png) [@marvy](https://community.plotly.com/u/marvy)\
**Post date:** [June 25, 2025, 6:37pm UTC](https://community.plotly.com/t/weeks-on-an-x-axes/92856/1 "2025-06-25T18:37:12Z")

</div>

I’m creating a line chart based on weekly data, using a custom week calendar (not the ISO standard). However, for weeks with no data, those timespans are not shown on the chart. This can be fixed, but what’s the best way to ensure that all weeks—regardless of whether they contain data—are still displayed on the timeline?

```auto
import plotly.express as px
import pandas as pd

# 
daily_df = pd.DataFrame({
    "date": pd.to_datetime(["2025-06-01", "2025-06-02", "2025-06-04"]),
    "value": [10, 20, 30]
})

fig1 = px.line(daily_df, x="date", y="value", markers=True, title="Dagelijkse Data met Gaten")

# --- Weekdata met weeklabels op de x-as ---
week_labels = ["202521", "202522", "202523"]
week_df = pd.DataFrame({
    "weeknr": week_labels,
    "value": [10, 20, 30]
})

fig2 = px.line(week_df, x="weeknr", y="value", markers=True, title="Wekelijkse Data met Weeklabels")

fig1.show()
fig2.show()

```

---

<div class="post-metadata">

**Author:** ![Xavi.LL](https://sea2.discourse-cdn.com/flex024/user_avatar/community.plotly.com/xavi.ll/32/31770_2.png) [@Xavi.LL](https://community.plotly.com/u/Xavi.LL)\
**Post date:** [June 25, 2025, 7:47pm UTC](https://community.plotly.com/t/weeks-on-an-x-axes/92856/2 "2025-06-25T19:47:58Z")

</div>

Hi @marvy , I don’t know if it’s what you exactly want, but maybe `datetime` library can solve your problem:

```python
import plotly.express as px
import pandas as pd
from datetime import datetime

# Input list of date strings
date_strings = ["2025-06-01", "2025-06-02", "2025-06-04"]

# Convert to "June 1, 2025" format
formatted_dates = [
    datetime.strptime(date, "%Y-%m-%d").strftime("%B %-d, %Y") for date in date_strings
]

# 
daily_df = pd.DataFrame({
    "date": formatted_dates,
    "value": [10, 20, 30]
})

fig1 = px.line(daily_df, 
               x="date", 
               y="value", 
               markers=True, 
               title="Dagelijkse Data met Gaten")

# --- Weekdata met weeklabels op de x-as ---
week_labels = ["202521", "202522", "202523"]
week_df = pd.DataFrame({
    "weeknr": week_labels,
    "value": [10, 20, 30]
})

fig2 = px.line(week_df, 
               x="weeknr", 
               y="value", 
               markers=True, 
               title="Wekelijkse Data met Weeklabels")

fig1.show()
fig2.show()

```

 ![Screenshot from 2025-06-25 21-46-40](https://us1.discourse-cdn.com/flex024/uploads/plot/original/3X/8/1/818a99047208497b6412c7f080bb1c4f9f0d8c9b.png)

---

<div class="post-metadata">

**Author:** ![Xavi.LL](https://sea2.discourse-cdn.com/flex024/user_avatar/community.plotly.com/xavi.ll/32/31770_2.png) [@Xavi.LL](https://community.plotly.com/u/Xavi.LL)\
**Post date:** [June 26, 2025, 2:12pm UTC](https://community.plotly.com/t/weeks-on-an-x-axes/92856/3 "2025-06-26T14:12:10Z")

</div>

Hi @marvy , I missunderstood your question. If I’m rights is the `fig2` the one you want to change. You can do that:

```python
import plotly.express as px
import pandas as pd
from datetime import datetime

# 
daily_df: pd.DataFrame = pd.DataFrame({
    "date": pd.to_datetime(["2025-06-01", "2025-06-02", "2025-06-04"]),
    "value": [10, 20, 30]
})

fig1 = px.line(daily_df, 
                          x = "date", 
                          y = "value", 
                          markers = True, 
                          title = "Dagelijkse Data met Gaten")

# --- Weekdata met weeklabels op de x-as ---
week_labels = ["202521", "202522", "202524"]
formatted_dates = []

for week_date in week_labels:
    year = int(week_date[:4])
    week = int(week_date[4:])
    date_obj = datetime.fromisocalendar(year, week, 1)
    formatted_dates.append(f"{date_obj.year}-{date_obj.month}-{date_obj.day}")

print(formatted_dates)
week_df: pd.DataFrame = pd.DataFrame({
    "date": pd.to_datetime(formatted_dates),
    "value": [10, 20, 30]
})

fig2 = px.line(week_df, 
                          x = "date", 
                          y = "value", 
                          markers = True, 
                          title = "Wekelijkse Data met Weeklabels")

fig1.show()
fig2.show()

```

 ![Screenshot from 2025-06-26 16-08-44](https://us1.discourse-cdn.com/flex024/uploads/plot/original/3X/f/f/ffc606873ae4bbacb70630a6b8d92ea5df236858.png)
