Part two!
Missed an issue? Back issues page 62!
Part two!
Missed an issue? Back issues page 62!
OUR EXPERT
Michael Reed has a neurological condition that means he does it all night long about 50% of the time -programming, that is.
QUICK TIPS
Visual Studio Code
displays a pop-up offering to install Python language extensions. We recommend allowing this because they are extremely helpful.
QUICK TIPS
Visual Studio Codedisplays a pop-up offering to install Python language extensions. We recommend allowing this because they are extremely helpful.
Last issue, we examined some applications that can help you record information about your workouts, sleep schedule and activity levels on your computer. This time, we’re going to look at processing and visualising that data, mainly using the Python programming language.
Many apps that record data can also plot the data, giving you an overview, but sometimes, you have niche requirements. This is where Python comes in, as it gives you a great deal of manual control over how you handle the data and how you plot it. Most logging software can export its data into a format such as CSV (commaseparated values), JSON (JavaScript Object Notation) or XML, and Python has modules that import these.
You’d be amazed how easy it is to use Python to plot data as a graph, once you’ve set it up and installed the requisite modules. Often, visualisation allows you to see patterns and trends that aren’t otherwise obvious. Matplotlib is the library that handles the plotting, and nearly every aspect of your plots can be customised. Once you know the basics, you might even find it easier than using a spreadsheet to plot data.
Python environment
Some distributions have the Python programming language installed by default, and if not, it’s possible that it will have been installed as a dependency of another package. The simplest way of determining if it is installed is to type python -V into a terminal.
It’s easy to install on most distributions by using the package manager. Python 3 was released in 2008, but because there were significant changes to how the language worked, Python 2 hung around for quite a long time. As a result, you typically have to specifically install the Python 3 package using a command such as sudo apt install python3 (Ubuntu).
In this case, we’re going to install the Python modules that we need, globally, to the entire system. Use your package manager to install these packages: python3-matplotlib, python3-numpy, python3scipy, python3-matplotlib and python3-dateutil.
We’ll assume that you’re using Visual Studio Code as your editor. You can add this in a number of ways, but the most problem-free approach is to download the DEB or RPM file from the official website (https:// code.visualstudio.com)and install it manually.
Plotting a simple example with made-up data. Matplotlib works out optimal x and y axis labels.