dsugasa
dsugasa

Reputation: 683

tickformat in Plotly Python

I am trying to format my Plotly Bar Chart x-axis to percentages with 3 decimal points.

import chart_studio.plotly as py #for plotting
import plotly.graph_objs as go


y = ['niner', 'deuce', 'checker']
x = [0.03, -0.05, 0.075]


fig = go.Figure(go.Bar(y = y, x = x,
            name = 'returns',
            orientation = 'h',
            marker = dict(color = '#003663',
                             line = dict(
                                      color = '#afafaf',
                                      width = 1.5)
                                    )))

fig.update_layout(
        title = 'Why So Hard Plotly?',
        xaxis = dict(
                tickformat = '%.format.%3f',
                title = 'Returns',
                fixedrange = True,
                hoverformat = '.3f',
                showgrid = True), 

        yaxis = dict(

                fixedrange = True,
                hoverformat = '.3f',
                showgrid = True,

        ),     
         bargap = 0.2, 
         barmode = 'relative',             
)
fig.update_yaxes(automargin=True) 
fig.show()

I can get the y-axis to appear as a rounded percentage using tickformat = '%', but I can't get more decimals to appears. The Plotly d3 documentation isn't clear (to me) how to do this. Any help is appreciated.

Thanks in advance.

Upvotes: 5

Views: 19920

Answers (1)

nicolaskruchten
nicolaskruchten

Reputation: 27370

I believe that setting tickformat to ".3%" should do it. Formatting 0.512345 this way yields 51.235%.

Upvotes: 7

Related Questions