'Display text values on stacked bar graph using plotly express in Jupyter notebook

I am working with plotly express in a Jupyter Notebook, doing a stacked bar chart. I'm trying to get the percentages in this sample data to display on the graph itself:

Sample Data:

Group Any Insurance Employment Based Medicaid Other
Group1 91.7 55.5 15.5 20.7
Group2 89.6 46.3 28.5 14.8
Group3 81.7 41.2 28.3 12.2
Group4 94.1 61.4 15.8 16.9

I've tried text= and textposition = 'auto', like below:

import pandas as pd
import plotly.express as px
import plotly.graph_objects as go

CG = pd.read_csv("CoverageGroups.csv", header=0)

    fig = go.Figure(data=[
    go.Bar(name='Employment Based', x=CG.Group, y=CG['Employment Based'], marker_color='silver', textposition = 'auto'),
    go.Bar(name='Medicaid', x=CG.Group, y=CG['Medicaid'], marker_color='grey', textposition = 'auto'),
    go.Bar(name='Other', x=CG.Group, y=CG['Other'], marker_color='silver', textposition = 'auto'),
])
# Change the bar mode
fig.update_layout(barmode='stack',
                   title='Coverage by Group',
                   xaxis_title='Group',
                   yaxis_title='% Covered',
                   plot_bgcolor='white',
                )
fig.show()

But my resulting figure doesn't have any of the percentages displaying on the bars as desired: Resulting figure



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source