Black Lives Matter. Please consider donating to Black Girls Code today.
https://www.blackgirlscode.com

Horizontal box plots log scale incorrect layout

Hi,

I am having a hard time with box plots and the logarithmic scale. I think there is a bug when plotting horizontal box plots with logarithmic scale. Plotting the graphs once in linear and once in log scale looks like this:

There is no padding on the left between the graph and the labels.
Code to reproduce looks like this:

data = []
for i in range(4):
    values = np.random.randn(10)
    indices = values
    title = f"Cat {i}"
    data.append((title, indices, values))


boxes = []
for title, indices, values in data:

    box = go.Box(
        x=values,
        name=title,
        boxpoints='outliers',
        text=indices,
        hoverinfo="text+x",
        marker=dict(
            outliercolor=colorconstants.RGB_COLOR_RED,
            line=dict(
                outliercolor=colorconstants.RGB_COLOR_RED,
                outlierwidth=2
            ),
        ),
        orientation='h',
    )
    boxes.append(box)

layout_xaxis=dict(
    automargin=True,
    zeroline=False,
    layout_xaxis["type"] = "log"
)

layout = go.Layout(
    width=1500,
    xaxis=layout_xaxis,
    yaxis=dict(
        automargin=True,
    ),
    paper_bgcolor="white",
    plot_bgcolor="white",
    showlegend=False,
)

return boxes, layout

Maybe this is related to some issues in plotly.js: https://github.com/plotly/plotly.js/issues/3508

Thanks

This is not a bug. If your values go down to 0, then it will go to negative infinity on a log scale and therefore go right to the edge of the graph since you have to define a certain range for the x-axis.

1 Like

I see. Thank you that helped. For all others: Pad in the margin attributes determines the distance between the plot and the labels: https://plotly.com/python/reference/#layout-margin-pad