✊🏿 Black Lives Matter. Please consider donating to Black Girls Code today.
⚡️ Concerned about the grid? Kyle Baranko teaches how to predicting peak loads using XGBoost. Register for the August webinar!

Add %/£/$ symbol to values

I have produced my bar charts via plotly express

The values I have are percentages and some are monetary values.

I am attempting to

  1. add in the symbol of % or £ to the values on the bar

  2. round the numbers to be no decimal places

def _bar_plot(df, **kwargs):

    combined_df = df.query("variable == 'bar plot'")

    fig = px.bar(combined_df, x="business", y="value", title="bar plot (%)", text="value", color="business",)


        hovermode="x",showlegend=False, autosize=True, yaxis=dict(tickformat=".2%")


    return plot(fig, output_type="div", include_plotlyjs=False)

Example below of wanting to change the percents below from 0.58 to 58%


Append the unicode for euro, pound, (https://www.fileformat.info/info/unicode/category/Sc/list.htm) and just '%' for percent, to each element in fig.data[0].text’, converted to string:

import pandas as pd
import plotly.express as px
df =pd.DataFrame(dict(product=['A', 'B', 'C'],   
                      value= [2000, 1400, 2300]))

fig = px.bar(df, x='product', y='value', text="value")
#print(fig.data[0].text) to see its actual definition, and update it as follows:
fig.update_traces(text= [f'{val}\u00A3' for val in df['value']])

Thanks for the comment.

I can see that the unicode addition does append properly.

The only issue i have is that it is now taking the wrong column values and not the one i want.

I have 2 columns which are the values from the model.
There is a third column that is an equation of col1+2, which is the results needed to be shown
Using the above unicode line, only returns results from col1

before unicode

after unicode


Could you paste, pls, your code for text definition/update, and write down how you want to be displayed the string for the third bar?