Matplotlib

“I had a polynomial once. My doctor removed it.”

Michael Grant, Gone

chris-liverani-NDfqqq_7QWM-unsplash-scaled-cropped.png

Matplotlib is a Python library for creating mathematical plots and it is documented on Wikipedia. I use it for visualization in, e.g., MAVProxy. It is a quicker alternative to heavy-duty mathematical tools such as MATLAB or Octave when you need to get a plot out to your boss quickly.

For VS Code, as matplotlib is unikely to support Python 2 past 2020, we must specify python3 by going to File > Preferences > Settings and then select the Python Extension from the User tab. Scroll down a bit and you will be able to specify python3 as the default interpreter. This is all documented very well on VS Code's website.

setPython3_vscode.png

Setting Python 3 in VS Code

If you should have any doubts about whether or not Python 3 is installed enter:

whereis python3

at a command prompt. If nothing is returned to the shell by the whereis or the which command, then Python 3 is either not installed or it's installed but Linux can't find it because it's installed in a custom location.

Today we are going to show how to use matplotlib together with MAVProxy. This will be done on Ubuntu 20.04.

First we need to install matplotlib on the system. At a terminal enter:

sudo apt install python3-matplotlib python3-numpy

Now install mavproxy. For detailed instructions on MAVProxy's installation please refer to the ArduPilot documentation. Note that you may need to run the following command via sudo.

pip install mavproxy

We are not going to spend time today going through the details on how to run MAVProxy: for that see the aforementioned ArduPilot docs. The reader is referred to the excellent sim_vehicle.py script provided with the ArduPilot Software In The Loop simulator.

Two sample matplotlib plots for your viewing pleasure:

altExample.png

Plot of relative altitude above the home point for a short ArduPilot flight.

speedAndAlt.png

Airspeed and altitude plots for a short ArduPilot flight. Note the speed scale is between 0 and 30 m/s and the altitude scale is between 0 and 700 meters.

Credits

https://code.visualstudio.com/docs/languages/python

Previous
Previous

g++ with MSYS & VS Code

Next
Next

Best Practices for Replacement Software Rollouts