1

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

1
  • 1
    ax2.text[10, 5, f"{df['gear'][0]:.1f}", ...) should do the trick. Commented Feb 3, 2021 at 7:02

1 Answer 1

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")
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.