If you face _tkinter.TclError when you run your python application based on MatPlotLib on CentOS 7, it might be caused by MatPlotLib choose Xwindows backend by default.

The error message will be like below:

$ python matplot_test.py
Traceback (most recent call last):
  File "matplot_test.py", line 3, in <module>
    plt.plot(["Seoul","Paris","Seattle"], [30,25,55])
  File "/usr/lib64/python2.7/site-packages/matplotlib/pyplot.py", line 3352, in plot
    ax = gca()
  File "/usr/lib64/python2.7/site-packages/matplotlib/pyplot.py", line 969, in gca
    return gcf().gca(**kwargs)
  File "/usr/lib64/python2.7/site-packages/matplotlib/pyplot.py", line 586, in gcf
    return figure()
  File "/usr/lib64/python2.7/site-packages/matplotlib/pyplot.py", line 533, in figure
    **kwargs)
  File "/usr/lib64/python2.7/site-packages/matplotlib/backend_bases.py", line 161, in new_figure_manager
    return cls.new_figure_manager_given_figure(num, fig)
  File "/usr/lib64/python2.7/site-packages/matplotlib/backends/_backend_tk.py", line 1046, in new_figure_manager_given_figure
    window = Tk.Tk(className="matplotlib")
  File "/usr/lib64/python2.7/lib-tk/Tkinter.py", line 1745, in __init__
    self.tk = _tkinter.create(screenName, baseName, className, interactive, wantobjects, useTk, sync, use)
_tkinter.TclError: no display name and no $DISPLAY environment variable


In order to solve this problem, you need to set MatPlotLib by following codes on top of your codes.

import matplotlib
matplotlib.use('Agg')

...
<your original code>