Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

matplotlib.pyplot title adjusts number of digits to display in floating points

I have been searched high and low to display only 2 digits of floating points. Here is a variable "enrichment", which is equal to 31.5925925926....... Is there any way just to display the following in matplotlib.pyplot?

Desired plot title:

ROC Curve; Enrichment factor 1% = 31.59

Here is the code

plt.title('ROC Curve; Enrichment factor 1% = '+str(enrichment))

This will show

ROC Curve; Enrichment factor 1% = 31.5925925926

Thanks!

like image 807
Chubaka Avatar asked Feb 11 '23 15:02

Chubaka


1 Answers

Matplotlib is irrelevant here. Just use string formatting

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

like image 117
Paul H Avatar answered Feb 14 '23 03:02

Paul H