✊🏿 Black Lives Matter. Please consider donating to Black Girls Code today.
📊 Dash 2.0 is Arriving. Register here.

Xaxis names on go.Bar

Hi everyone,

I’m having some struggles setting the right names in a go.Bar figure, here is my problem: I used a list of strings for my x values but on the figure displayed other values are also shown (the ones with the red crosses underneath them (see figure))

Here is the code that I use:

 annee_nbc = {2014: 925, 2015: 81}
 fig_nbc = go.Figure(
            data=[go.Bar(x=[str(a) for a in annee_nbc.keys()], y=list(annee_nbc.values()), marker_color='#BA4A0D')],
            layout={'margin' : {"r":45,"t":45,"l":45,"b":45},'plot_bgcolor':'rgba(0,0,0,0)'}

And here is the result that I obtain:

I feel that my problem is pretty simple, but I cannot seem to find the answer by myself, does anybody have any idea how to solve it?

Hi @Cloemdz

If you declare xaxis_type='category' you’ll get the right bar chart:

import plotly.graph_objects as go
annee_nbc = {2014: 925, 2015: 81}
fig = go.Figure(go.Bar(x=[str(a) for a in annee_nbc.keys()], y=list(annee_nbc.values()), marker_color='#BA4A0D')
1 Like

Omg that’s it thank you so much!!