plotly / plotly/plotly.py

tickvals and ticktext don't work with subcategory axes

Open
#2,395 5 comments 9 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug P3
Dominant language
Python
Stars
18.8k
Forks
2.8k
Avg merge
16h 26m
Merged PRs (30d)
21

Description

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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the single-category and multi-category examples in the issue and compare the resulting axis behavior. Trace how multi-category axes process xaxis.tickvals, ticktext, and showticklabels; done means tickvals and ticktext work for multi-category plots and individual category labels can be hidden.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
data-visualization
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.