✊🏿 Black Lives Matter. Please consider donating to Black Girls Code today.
⚡️ Concerned about the grid? Kyle Baranko teaches how to predicting peak loads using XGBoost. Register for the August webinar!

Control label cutoff when width changes

Hello.
We are often creating barplots with very long labels, in particular we use horizontal barplots to fit them. They should resize dynamically, e.g. for displaying them in Dash

When the label is too long, it gets cut off, which makes sense: but, i think the default behaviour is a bit rough, it almost looks like a bug.

The below example shows the problem, where a small width change creates a very worse outcome, while there are at least two ways to make it look better: (1) shrink the plot area even further, (2) cut off a smaller fraction of the label.

I did try the Automargin keyword, but i don’t think it’s what i’m looking for.

My questions are:

  1. is this behaviour controllable in any way? Even a workaround would work for us (it should work dynamically though).
  2. Would it be useful if i opened a Github Issue about this problem?

Self contained code:

import plotly.graph_objects as go
yy = ["this::::::: ____ will be cut away::OOOOOOOOOOO______:Apples",
              "this::::::: ____ will be cut away::OOOOOOOOOOO______:Oranges",
              "this::::::: ____ will be cut away::OOOOOOOOOOO______:Bananas",
              "this::::::: ____ will be cut away::OOOOOOOOOOO______:Pears",]
xx = [4, 1, 2, 5]
go.Figure([go.Bar(orientation='h', x=xx, y=yy)], 
                go.Layout(width=900)) 
go.Figure([go.Bar(orientation='h',  x=xx, y=yy)], 
                go.Layout(width=800))

Thanks!

1 Like