如何编写嵌套字符串格式?



我在plot中使用下面的字符串格式。

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

现在我喜欢将num of digit设置为变量,所以我必须使用像这样的嵌套字符串格式,它不起作用。谢谢你的帮助。

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

我会尝试使用round函数:texttemplate='%{round(text, num_digit)}'

编辑:以下作品:

texttemplate='%{text:.' + str(num_digit) + 'f}'

最新更新