How to change point separator for the y-axis of a Plotly figure?

PM92

I've been working on a graph for days to summarize some results. However, I just got stuck trying to change the y-axis separator to "," instead of "."

I resorted to ChatGPT, as I don't have that much skill with the Plotly library, in Python, however, the solutions he presented still did not correct the problem.

In any case, here's the complete code for anyone who can help me. The graph is generated right after execution.

Greetings!

import plotly.graph_objects as go
from plotly.offline import plot

data = [
    ['TabNet', 0.6589, 'FT-Transformer', 0.6570, 'NODE', 0.6347, 'TabTransform', 0.6338, 'MLP', 0.6310, '1D-CNN', 0.5911],
    ['TabNet', 0.6347, 'MLP', 0.6115, '1D-CNN', 0.6013, 'NODE', 0.5315, 'FT-Transformer', 0.2871, 'TabTransform', 0.2156],
    ['TabNet', 0.6645, 'TabTransform', 0.6589, 'NODE', 0.6542, 'FT-Transformer', 0.6421, 'MLP', 0.6050, '1D-CNN', 0.5957],
    ['FT-Transformer', 0.6570, 'TabNet', 0.6525, 'TabTransform', 0.6254, 'NODE', 0.6236, 'MLP', 0.5827, '1D-CNN', 0.5780],
    ['TabNet', 0.6672, 'NODE', 0.6515, 'FT-Transformer', 0.6375, 'MLP', 0.6338, '1D-CNN', 0.5743, 'TabTransform', 0.3503]
]

strategies = ['TA/HI', 'PCA', 'SA', 'UNDER', 'OVER']

architectures = ['1D-CNN', 'FT-Transformer', 'MLP', 'NODE', 'TabNet', 'TabTransform']

colors = {
    '1D-CNN': '#8c564b',
    'FT-Transformer': '#ff7f0e',
    'MLP': '#9467bd',
    'NODE': '#2ca02c',
    'TabNet': '#1f77b4',
    'TabTransform': '#d62728'
}

fig = go.Figure()

for i in range(len(architectures)):
    y_values = []
    text_values = []
    color_values = []
    for j in range(len(strategies)):
        strategy = strategies[j]
        for k in range(len(data[j]) // 2):
            if data[j][k*2] == architectures[i]:
                y_values.append(data[j][k*2+1])
                text_values.append("{:.2%}".format(data[j][k*2+1]).replace('.', ','))
                color_values.append(colors[architectures[i]])
                break
    fig.add_trace(go.Bar(
        name=architectures[i],
        x=strategies,
        y=y_values,
        text=text_values,
        textposition="outside",
        textangle=0,
        textfont=dict(size=14),
        marker=dict(color=color_values)
    ))

fig.update_layout(
    font=dict(size=10),
    plot_bgcolor='rgba(0,0,0,0)',
    barmode='group',
    bargap=0.15,
    bargroupgap=0.1,
    legend=dict(orientation='h', yanchor='bottom', y=1.02, xanchor='center', x=0.5),
    margin=dict(t=100)
)

fig.update_layout(yaxis=dict(tickformat='.2%'))

for annotation in fig['layout']['annotations']:
    annotation['text'] = annotation['text'].replace('.', ',')

fig.show()
5eb

Update the separators of the figure layout:

fig.update_layout(yaxis=dict(tickformat='.2%'), separators=",")

separators – Sets the decimal and thousand separators. For example, *. * puts a ‘.’ before decimals and a space between thousands. In English locales, dflt is “.,” but other locales may alter this default.

https://plotly.com/python-api-reference/generated/plotly.graph_objects.Layout.html

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

How to change the decimal separator of DecimalFormat from comma to dot/point?

Plotly: How to change legend without changing figure data source?

How to change axis limits and tick step of a MatLab figure?

How to change axis features in plotly?

Change y-axis tick values of a heatmap with R/Plotly

Plotly: How to set the range of the y axis?

How to change the position of y axis label to be directly on top of the y axis?

Plotly: How to plot a multiple y axis?

Plotly: How to change the format of the values for the x axis?

Plotly: How to change figure size?

How to change the default line style for every plotly figure in a r file

how to change color of axis in 3d matplotlib figure?

Plotly: How to hide axis titles in a plotly express figure with facets?

how to change thousands separator for blank in R plotly?

Plotly: Change y-axis scale

How to change x-tick labels to custom labels, in plotly figure

In ggplot2, how to add another y-axis in the figure?

How to change the axis values of matplotlib figure?

Change format of y axis in plotly

Plotly-px. plot: Sharing x- axis plotting different y-values with button choice and all belonging to the same figure- How?

Plotly: How to change the range of the y-axis of a subplot?

how to Change matplotlib.figure.Figure objects axis names

How to change the x-axis and y-axis labels in plotly?

How to dynamically change the scale/ticks of y axis in plotly charts upon zooming in?

plotly express | change tick units on y axis

Change subplot y axis text via dropdown selection in plotly

Change y-axis title hover in histogram plotly python

Vega-Lite (Deneb for PowerBI) - How to change the starting point of the Y-Axis?

How to add figure labels above Y axis in multi panel plot