Matplotlib and Visual Studio Code

The commands on the following page has been performed and tested with the following versions:

Installation and configuration of Python and Visual Studio Code has been perfomed by following this step by step guide.

Update your system

Start by updating your system:

sudo apt update
sudo apt upgrade

Install matplotlib

If you work with virtual environments, do not forget to activate your environment before installing matplotlib, otherwise it will be installed system wide. The following command installs matplotlib:

sudo apt install python3-matplotlib

or:

python -m pip install -U matplotlib

Create and run the following Python script:

import matplotlib.pyplot as plt
plt.plot([1, 2, 3, 4])
plt.ylabel('some numbers')
plt.show()

If the chart is not displayed or if you get the following error UserWarning: Matplotlib is currently using agg, which is a non-GUI backend, so cannot show the figure. install tkinter:

sudo apt-get install python3-tk

The script should now display the following figure:

Figure display with matplotlib

See also


Last update : 02/21/2020