https://stackoverflow.com/questions/21784641/installation-issue-with-matplotlib-python
I assume you have installed the pip matplotlib, there is a directory in you root called ~/.matplotlib.
Create a file ~/.matplotlib/matplotlibrc there and add the following code: backend: TkAgg