Black Lives Matter. Please consider donating to Black Girls Code today.
Learn how to use COVID-19 data in open source Dash apps. Register for the Sept 23rd webinar with IQT!

Want to change y axis values

I am trying to graph horizontal bar chart. There are id values that should be on y axis and x axis should cointain count. My idea is to get text descriptions on y axis instead of id values. So I was thinking of making like a dictionary, specifying what id should translate to what text value :slight_smile:

here is part of code:

def update_figure(bar):
    filtered_df = df[df.academic_year == bar]
    count = filtered_df['working_place_id'].value_counts()
    name = filtered_df['working_place_id']

    return {
        'data': [
            {'x': count,
            'y': ['0': 'no data',
                '2' : 'blah1',
                '3' : 'something',
                '4' : 'else',
               ]},
            'type': 'bar',
            'orientation': 'h'
            }],
        'layout':
        go.Layout(title='horizontal graph')

But ofcourse I am defining y values wrong and it does not work. Am I trying to do the impossible? What is the right way to “map” values so to say?

Hi , Just suggesting an idea here. Not sure if it will help you.

Create new columns with the integer name_ids in the DF

available_names=filtered_df[‘working_place_id’].unique()
max_temp_names=len(avaiable_names)
names_k ={available_names[m]: m for m in range(max_temp_names)}

df[‘name_id’] = df[‘working_place_id’.map(names_k)]