As reported here, when you use Anaconda, install the packet using conda. In this case, the right instruction to use (on Ubuntu 18.04) is:
conda install -c conda-forge matplotlib
This will solve the problem.
If you use pip
(you can), you will mess up all the dependencies (and for instance, the probability that other scripts/programs do not work anymore is not null: if you use Spyder, you will have big dependencies problem to face).
Optional:
In order to always avoid problem like this, I recommend you to use Virtual Enviroment:
Whats is it?
Geeksforgeeks explains it clearly.
How?
A step-by-step guide is always useful.