Display custom labels for each column in a histogram

I already have a histogram that looks like this:
Screenshot 2023-10-02 at 12.05.58

The data comes from reading an XLS file that looks like this:

Month      |  Role        |    Quantity
-----------------------------------------------
January       Engineer      10
January       Lawyer        2
January       Doctor        2
February      Engineer      9
February      Lawyer        4
February      Doctor        1
March         Engineer      6
March         Lawyer        3
March         Doctor        7

I’m doing it like this:

df = pd.read_excel(path_to_xls, sheet_name="Sheet1")
pivot = df.pivot_table('fte', ['month'], 'role')
    fig = px.bar(pivot,
                 x=pivot.index,
                 y=pivot.columns,
                 labels={"month": "Months before SOP", "value": "FTE"},
                 barmode="stack")

    fig.update_layout(showlegend=True,
                      legend_title_text="Roles",
                      #showline=True,
                      plot_bgcolor = "rgba(0, 0, 0, 0)",
                      paper_bgcolor = "rgba(0, 0, 0, 0)")

Now I have to add another column to the XLS with a custom label to display for each column, so that, in the X-axis, instead of displaying 0, 1, 2, 3, 4 … I can display whatever text comes in that new column field. eg: “-2 months, -1 month, Start of Project, 1 month, 2 months,…, End of Project”.

Please, any idea how to do this?

HI @Ricardo, you can do this with with tickmode = 'array'

2 Likes

Thank you @AIMPED ! Exactly what I needed :slight_smile:

1 Like