_tkinter.TclError: couldn't connect to display "localhost:11.0"
Python tried to create an interactive figure window, which fails because you work on a server or screen session without graphical output (no X11 display).
If you only want to plot figures to files (pdf, png,..), set matplotlib screen output to 'Agg' before importing pylab or pyplot.
import matplotlib
matplotlib.use('Agg')
import matplotlib.pyplot as plt
plt.plot([1,4,3,6,12,20])
plt.savefig('plot.pdf')
http://matplotlib.org/faq/howto_faq.html#generate-images-without-having-a-window-appear