Make Readable Results#
Python 3’s f-Strings: An Improved String Formatting Syntax (Guide) - https://realpython.com/python-f-strings/
Your professors are old and their eyes are bad—why torture them with thin lines and tiny text on your figures?
There are courses and books devoted to this Golden Rule, not to mention professional editors and typesetters. While you should aways make sure your results are readable, there are three main categories where it is easy to make significant improvements to readability and communication: figures, tables and numbers.
Figures#
You’ve gone through all the work to write code, run analyses, collect results and present them in figures. Why not spend a little extra effort to make the figure easy for your reader or audience to interpret? You should always make sure a figure contains enough information for a viewer to understand the main variables even if taken out of context, which can be done easily by including axis labels and a title, both with units, as well as a legend. Use of high contrast colors, symbols and line types is important if a lot of curves or data types are included. Finally, depending on the importance and use consider: setting good axis limits and increments (e.g., tics every 5 instead of 7), equal scale axes, grid lines, etc.
Our advice is to get in the habit of always adding a few simple commands to format to make it easy to repeat when it matters. Rather than take up space here with examples, keep an eye out for nicely formatted figures in MUDE notebooks.
Tables#
Similar to figures, make sure key information about the contents such as variable name, type and units are included. Limiting the number of significant figures to 3, adding more only when needed, can significantly improve the readability of a table. There are a number of tools available for creating tables, so we encourage you to use Google to find a few that work for your working method.
Significant digits#
Did you know that computers can store decimals up to 16 digits? If you let it, Python will try to return as many of these digits as possible. When you present results of your calculation with 6 or 8 decimal values, you give a false (and at times silly) impression of precision. For example, is that wind speed really 14.4613587 m/s? Especially when the accuracy of the sensor is +/-10% and the wind is gusting significantly? For most engineering purposes, 3 significant digits is plenty and can be considered a default. You can always add more if you have a good reason to do so.
Fortunately Python has a great tool to help you use an appropriate number of significant digits: f-strings
. A few quick examples are provided below, and you can read more about f-strings here, or any of the other good resources online.
from math import pi
# Easiest f-string:
print(f'Add f before string, use curly braces to round pi = {pi:.3f}')
print(f'Different formats are possible, pi = {pi:.3e}\n')
three_things = [1.21581651, 3.8, 3.43454]
print('Unpack all numbers using the same format:')
print(*[f'{i:.3f}' for i in three_things])
print('\nNow list each on a separate line:')
print(*[f'{i:.3f}' for i in three_things], sep='\n')