Matplotlib
“I had a polynomial once. My doctor removed it.”
― Michael Grant, Gone
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.
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:
Credits
https://code.visualstudio.com/docs/languages/python