Formating decimal separator in xticks when plotting with PlotlyJS

Hi all, I have the dataset as follow:

df = DataFrame(
    kvkt = [
        "Service", "Service", "Service", "Service", "Service",
        "Manufacturing", "Manufacturing", "Manufacturing", "Manufacturing", "Manufacturing",
        "Agriculture", "Agriculture", "Agriculture", "Agriculture", "Agriculture"
    ],
    year = [2017, 2018, 2019, 2020, 2021, 2017, 2018, 2019, 2020, 2021, 2017, 2018, 2019, 2020, 2021],
    mean_turnover = [1.3, 1.3, 1.2, 1.1, 1.7, 1.3, 1.2, 1.0, 0.9, 1.4, 1.0, 1.2, 1.2, 1.5, 1.1]
)

I want to change xticks in this plot from dot to decimal, such as “1.3” to “1,3”. I got the plot below with the following code:

p_turnover_k = Plot(
                df, x=:year, y=:mean_turnover,
                color=:kvkt,
                text=:mean_turnover,
                kind="bar",
                textposition="auto",
                labels=Dict(
                    :year => "Year",
                    :mean_turnover => "Turnover rate",
                    :kvkt => "Sector",
                ),
                Layout(barmode = "stack", 
                font_family = "Courier New",
                separators = ",",
                legend = attr(
                    x=1,
                    y=1.02,
                    yanchor="bottom",
                    xanchor="right",
                    orientation="h"
                )
                )
)

I tried the docs in PlotylyJS and found about formatting xticks for thousand number but not for my case. Thanks.

I don’t know of a way to do the change within plotly, but you can do it from julia as:

df.mean_turnover_text = replace.(string.(df.mean_turnover), "." => ",")

then change

to
text=:mean_turnover_text

1 Like