swcarpentry / python-novice-gapminder

Plotting and Programming in Python
http://swcarpentry.github.io/python-novice-gapminder/
Other
165 stars 431 forks source link

Use of EngFormatter in plots for readability #399

Open jonititan opened 5 years ago

jonititan commented 5 years ago

Plotting within python using pyplot includes some very powerful functions useful to scientists and engineers. One in particular which I have found excellent for improving the readability of my plots and also for formatting of data into strings and messages is the EngFormatter function. It is a tick formatter in pyplot and has the obvious benefits shown for improving intelligibility of plots. It can be used outside of the plot figure environment to format numbers for strings in the following way.

from matplotlib.ticker import EngFormatter formatter_freq = EngFormatter(unit='Hz') print("Frequency is {}".format(formatter_freq(1000000)))

result is "Frequency is 1 MHz"

If this would be a welcome change I can work in an update to submit. I think it would fit best in chapter 9.

jonititan commented 5 years ago

I have had feedback from other instructors that this change and indeed the use of .format() on strings is too high level for this lesson. I can certainly see that argument but the more I read this lesson with the other Python programming lesson the more I see there is a high degree of overlap with python-novice-inflammation

alee commented 5 years ago

I think format strings are great, and definitely something to point learners at as a "would you like to learn more...".

Thoughts from other maintainers?