Skip to content

tickvals and ticktext don't work with subcategory axes #2395

Open
@krisowski

Description

@krisowski

If a plot has multi-category axes there is no way to hide a subcategory labels only and the plot doesn't render at all if tickvals and ticktext are used.

Look at the code without multi-categories:

x_names = ['very.long.name.1', 'very.long.name.2', 'very.long.name.3']
fig = go.Figure(go.Bar(
    x=x_names,
    y=[10, 20, 30]))
fig.update_layout(
    xaxis=dict(
        tickvals=x_names,
        ticktext=['', '', ''],
    ))

This works fine and all x-axes labels are hidden. I could achieve the same thing with this:
fig.update_layout(xaxis=dict(showticklabels=False))

However, if this is a multi-category plot it doesn't work at all:

x_names = [['A', 'A', 'B'], ['very.long.name.1', 'very.long.name.2', 'very.long.name.3']]
fig = go.Figure(go.Bar(
    x=x_names,
    y=[10, 20, 30]))
fig.update_layout(
    xaxis=dict(
        tickvals=x_names,
        ticktext=[['A', 'A', 'B'], ['', '', '']],
    ))

Setting showticklabels=False hides everything and I didn't find a way to hide just a single category labels.

What is really surprising this doesn't work either even if this doesn't change anything:

x_names = [['A', 'A', 'B'], ['very.long.name.1', 'very.long.name.2', 'very.long.name.3']]
fig = go.Figure(go.Bar(
    x=x_names,
    y=[10, 20, 30]))
fig.update_layout(
    xaxis=dict(
        tickvals=x_names,
        ticktext=x_names,
    ))

I believe it should work like this:

  • tickvals and ticktext work fine with a multi-category plots
  • showticklabels should accept a list of booleans, .e.g. [True, False] to be able to hide a given subcategory if this is a multi-category plot

Metadata

Metadata

Assignees

No one assigned

    Labels

    P3backlogbugsomething broken

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions