[SOLVED] Insert space between ticklabel and y-axis


I have a horizontal stacked bar graph with category labels (text) on the Y-axis. Currently the labels almost touch the Y axis line. Is there a way to insert some space between the Y-axis and the tick labels?

1 Like

So to answer my own question, I finally did this by turning OFF the ticklabels and using annotations to achieve the effect.

One has to play around with the domain of the x-axis and the placement of the labels depending on the length of text of the labels on the y-axis. In case this helps someone in the future, here is what I did:

layout = go.Layout(
              domain=[0.04, 1]     # play with the value of 0.04 if your labels are longer
annotations = []
# y_data is a list that contains the y-axis labels
for yd in y_data:
    # labeling the y-axis
    annotations.append(dict(xref='paper', yref='y',
                            x=0.03, y=yd,     # smaller values of x will give more space between y-axis and label
                            font=dict(family='Arial', size=14,
                                             color='rgb(67, 67, 67)'),
                            showarrow=False, align='right'))

layout['annotations'] = annotations
fig = go.Figure(data=data, layout=layout)
1 Like

An easier option would be to show the tick marks, but in the same color as the background:

yaxis = dict(ticks = "outside", tickcolor='white', ticklen=10)

What a clever solution!

Hi, I solved it by using

margin = {'pad': 20}

Source: stackoverflow

Hope this helps!


Thank you so much, searched a lot to find this!

1 Like