Remove Data from X Axis Labels plotly

Advertisements

enter image description hereIs there a way to remove the x axis data from the x axis? I need the labels, just not the data/volume. (i.e display "Example A", not "Example A 7000")

labels = ["Example A","Example B","Example C","Example D","Example E","Example F","Example G","Example H","Example I","Example J","Example K","Example L","Example M","Example N","Example O","Example P","Example Q","Example R","Example S","Example T",]
widths = np.array([7000,5000,4000,4000,3000,2000,2000,2000,2000,1800,1700,1500,1300,1200,1200,1100,1000,1000,1000,1000,])
data = { "5": [20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20],
"4": [20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20],
"3": [20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20],
"2": [20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20],
"1": [20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20],}
fig = go.Figure()
for key in data:
fig.add_trace(go.Bar(
    name=key,
    y=data[key],
    x=np.cumsum(widths)-widths,
    width=widths,
    customdata=np.transpose([labels]),
    textposition="inside",
    insidetextanchor = "middle",
fig.update_xaxes(
tickvals=np.cumsum(widths)-widths/2,
ticktext= ["%s<br>%d" % (l, w) for l, w in zip(labels, widths)])
fig.update_layout(
barmode="stack",
uniformtext=dict(mode="hide", minsize=18),
height = 1000,
width = 2000,)

>Solution :

You’re explicitly including the widths as labels in this line:

["%s<br>%d" % (l, w) for l, w in zip(labels, widths)]

Change that to:

["%s" % l for l in labels]

And it should work

Leave a ReplyCancel reply