Black Lives Matter. Please consider donating to Black Girls Code today.

Stripping off the m at the end of the numbers in Sankey Diagram

When making a Sankey graph in plotly if your values are below 1.0, Sankey will add an m to the end of the number and represent it as a whole number. I am wondering if there is any way to strip the m off the end of the number and as well show my number as a decimal. You can see an example in the screenshot below and my code that goes along with it.

data = dict(
node = dict(
pad = 15,
thickness = 20,
line = dict(
color = “black”,
width = 0.5
label = [“a”, “b”, “c”, “d”, “e”, “f”, “A”, “B”, “C”, “D”, “E”, “F”, “AA”, “BB”, “CC”, “DD”, “EE”, “FF”],
color = [“green”, “blue”, “red”, “orange”, “purple”, “pink”, “blue”, “blue”, “blue”,“blue”, “blue”, “blue”, “blue”, “blue”, “blue”, “blue”, “blue”,
link = dict(
source = Source,
target = Target,
value = Value,

layout = dict(
title = “Sankey Diagram”,
font = dict(
size = 10

fig = dict(data=[data], layout=layout)
py.iplot(fig, validate=False)

Hi @illsci-1,

You can do this using the valueformat property. You can set this to a format string according to If you just want decimal notation, set it to 'r', or if you want to specify a fixed number of significant digits (3 in this example) set it to '.3r'.

Hope that helps!

Hey Jon, thank you for the response. I have attached a picture of my sankey code where I tried putting valueformat = “.3r” under the layout dict as well as the data dict. The problems are still there unfortunately. Where should I be adding in this new line of code?



Hi @illsci-1,

The valueformat property is a top-level property of the sankey trace (you have it as a top-level layout property in this example). Something like

data = dict(

Also, I’d recommend removing the validate=False argument from iplot so that you’ll get validation error messages for invalid properties.

Hope that helps!

1 Like

Thank you very much Jon, that worked perfectly.


1 Like