How to change unit in vertical text

Hi
I’m using this code to display a bar chart. How can I customize left size unit (from M to millions-in-my-native-language) because my client is not using English ?

import plotly.express as px

df = px.data.gapminder().query("continent == 'Europe' and year == 2007 and pop > 2.e6")
fig = px.bar(df, y='pop', x='country', text='pop')
fig.update_traces(texttemplate='%{text:.2s}', textposition='outside')
fig.update_layout(uniformtext_minsize=8, uniformtext_mode='hide')
fig.show()

1 Like

Hi @hao.dn,

This is the right update to set a country specific thousands separator:

fig.update_yaxes(yaxis = dict(exponentformat= "none", 
                              separatethousands= True)

It replaces 80M by 80,000,000.

But if in your country thousands are separated by a dot, i.e. 80.000.0000, then this layout update must be performed, too:

fig.update_layout(separators =',.')

2 Likes

thank but actually I want to replace M (millions) to my native language. How can I archive that ?

@hao.dn

Could you please tell us how are denoted millions in your country?

in my country we use Tr (short of β€œTriệu” - millions ) instead M (short of β€œMillions”).

@hao.dn
In this case in the yaxis definition, set the attributes tickvals and ticktext as follows:

yaxis_tickvals= [10000000*k for k in range(1, 8)]  #these are the positions where the strings in tiktet will be placed
yaxis_ticktext=['10Tr', '20Tr' '30Tr', '40Tr', '50Tr', '60Tr', '70Tr', '80Tr']