I am looking for help in changing the thousands separator for numeric values in Plotly's Python distribution. I can change the default value format (".3s") to display comma-thousands-separated numeric values. I need a dot.
import plotly.graph_objects as go
import locale
locale.setlocale(locale.LC_ALL, 'de_DE')
print(locale.getlocale())
fig = go.Figure(data=[go.Sankey(
valueformat = ",",
node = dict(
pad = 15,
thickness = 20,
line = dict(color = "black", width = 0.5),
label = ["A1", "A2", "B1", "B2", "C1", "C2"],
color = "blue"
),
link = dict(
source = [0, 1, 0, 2, 3, 3],
target = [2, 3, 3, 4, 4, 5],
value = [8000, 7000, 6000, 5000, 4000, 2000],
color= ["red", "green","yellow", "magenta","red", "green"]
))]
)
fig.update_layout(title_text="Missing thousands dot-separated numeric values", font_size=10)
fig.show()
Fix attempts: Reading in on Plotly's graph objects Figure documentation, the valueformat attribute is where to apply those changes. However, for numbers Plotly just references d3-format, which directs to a README for Javascript implementations. So that's a dead end imo.
Then, I read in on changing my locale to a language which uses dot-separated-thousands. This seems to offer some alleviation to the problem, however this seems unsuitable, because I am sharing my project with people/across different operating systems. On my Ubuntu 20.04 my locale is Spanish, and the encoding of my German language pack when setting my locale's LC_ALL to 'de_DE'
is not UTF-8
but ISO8859-1
.
So ideally, I want to solve the separator issue within Plotly or find a robust fix which works across different oS.
Best regards, Fabian