1

I used below for string formatting in plotly.

texttemplate='%{text:.2f}'

now I like to set num of digit as a variable so I have to use nested string format like this, it didn't work. Thanks for your help.

num_gigit=f(key)
texttemplate='%{text:.{num_digit}f}'

1 Answer 1

3

I would try to use the round function: texttemplate='%{round(text, num_digit)}'

Edit: The following works:

texttemplate='%{text:.' + str(num_digit) + 'f}'
Sign up to request clarification or add additional context in comments.

6 Comments

sorry it doesn't work, not sure why?
Do you need to keep the percentage sign and curly brackets for plotly? If so: texttemplate='%{' + str(round(text, num_digit)) + '}' Otherwise: texttemplate=str(round(text, num_digit))'
I just thought of another possible solution: texttemplate='%{text:.' + str(num_digit) + 'f}'
Hi Nicolas, yes this latest one (texttemplate='%{text:.' + str(num_digit) + 'f}') works! Thank you so much! Please changed the answer so I can vote
@roudan Great! Answer changed.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.