Skip to content
Advertisement

How to format a number from thousands to K style in plotly

I want to change the format of y-axis from thousands to thousands in K format in plotly python.

enter image description here

Advertisement

Answer

Since you didn’t provide any data, or even explain what you want to show exactly on the y-axis, I will answer with what should work:

JavaScript

If you want regularly-spaced tick values for the y-axis, you can either pass a list of values, or use dtick and tick0, which are explained in the documentation

So for example, you might use

JavaScript

For tick values in steps of 1000, starting at 100000, ending at 999000, trimming insignificant trailing zeros.

Note that the K suffix will switch to M once the tick values reach into the millions, and so on. If you always want to use K, you’ll need to define your own using the ticktext parameter:

JavaScript

This will comma-separate and format numbers in thousands and append 'K', for example, 15485000 becomes '15,485K'.

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement