Hints for Exercise 9¶
General hints¶
Formatting numbers in Python¶
As you may have noticed, the numbers you add to your plot using the plt.text()
command look kind of ugly with so many digits after the decimal place.
You can make them look a bit nicer by rounding them when you call the plt.text()
command.
This is called formatted output in Python, and it is nice not only because it can make your text easier to read, but also because the formatting does not change the data values themselves, only their display.
To help you in formatting your output for your plots, here are some examples of how the output formatting works.
In [1]: import numpy as np
In [2]: pi = np.pi
In [3]: print('The value of pi is', pi)
The value of pi is 3.141592653589793
In [4]: print('The rounded value of pi is {0:.2f}'.format(pi))