matplotlib.pyplot title调整要在浮点中显示的位数

Chu*_*aka 3 python floating-point matplotlib title

我被高低搜索,只显示2位浮点数.这是一个变量"浓缩",等于31.5925925926 .......有没有办法在matplotlib.pyplot中显示以下内容?

期望的情节标题:

ROC Curve; Enrichment factor 1% = 31.59
Run Code Online (Sandbox Code Playgroud)

这是代码

plt.title('ROC Curve; Enrichment factor 1% = '+str(enrichment))
Run Code Online (Sandbox Code Playgroud)

这将显示

ROC Curve; Enrichment factor 1% = 31.5925925926
Run Code Online (Sandbox Code Playgroud)

谢谢!

Pau*_*l H 7

Matplotlib在这里无关紧要.只需使用字符串格式

plt.title('ROC Curve; Enrichment factor 1% = {:.2f}'.format(enrichment))