Using variables instead of dates in Gantt Charts

I want to assign a month as M0, and use notation like M1, M2, etc. on the Gantt chart and not rely on dates. How can I do it?

Hello @aupadhya welcome to the forums. You can set the tick labels manually:

import pandas as pd
import plotly.express as px

# 1. Define your data using standard date strings
# Each month corresponds to a specific date range (e.g., Month 0 = Jan, Month 1 = Feb)
df = pd.DataFrame(
    [
        dict(
            Task="Market Research",
            Start="2026-01-01",
            Finish="2026-02-15",
            Resource="Team A",
        ),
        dict(
            Task="Product Design",
            Start="2026-02-01",
            Finish="2026-04-01",
            Resource="Team B",
        ),
        dict(
            Task="Development",
            Start="2026-03-15",
            Finish="2026-06-01",
            Resource="Team C",
        ),
    ]
)

# 2. Create the timeline Gantt chart
fig = px.timeline(
    df, x_start="Start", x_end="Finish", y="Task", color="Resource"
)
fig.update_yaxes(
    autorange="reversed"
)  # Keeps the first task at the top

# 3. Map the calendar dates to your custom month aliases
# We define the specific date positions (tickvals) and their labels (ticktext)
tick_values = [
    "2026-01-01",
    "2026-02-01",
    "2026-03-01",
    "2026-04-01",
    "2026-05-01",
    "2026-06-01",
]
tick_labels = ["m0", "m1", "m2", "m3", "m4", "m5"]

# 4. Apply the custom ticks to the X-axis
fig.update_xaxes(
    tickmode="array",
    tickvals=tick_values,
    ticktext=tick_labels,
    title_text="Project Timeline",
)

# Show the chart
fig.show()