0

I have data set call 'df' and trying to use one of column data as a axis of graph.

The data appear on a graph as 11.58 so I would like to change it to one decimal place which is 11.5

Here is the code I've got.

if df['gear'] is no None:
    ax2.text[10,5, df['gear'][0], size=5, weight='bold', color='black', rotation=0., ha="center", va="center")

To change it to one decimal place, I've tried it as below but it won't work

if df['gear'] is no None:
        ax2.text[10,5, df['gear'][0], "{:.1f}", size=5, weight='bold', color='black', rotation=0., ha="center", va="center")

can someone please tell me how to change decimal point in ax.text. Thanks

H.Cho
  • 19
  • 1
  • 7

1 Answers1

1

use round function to round off the value to one decimal position

round(number, number of digits)
ax2.text[10,5, round(df['gear'][0], 1), size=5, weight='bold', color='black', rotation=0., ha="center", va="center")
kiranr
  • 2,087
  • 14
  • 32