I had this exact same problem. It only happens on macOS for me. I can run the program fine in Windows, but not Mac. I tested different versions of matplotlib to no avail. I wanted to test against the "classic" version of wxpython but I couldn't get it to download correctly from SourceForge.
I got around it by importing matplotlib inside of my function that did the plotting. This ran without errors but also produced some informative warnings:
/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/matplotlib/cbook/deprecation.py:107: MatplotlibDeprecationWarning: The WX backend is deprecated. It's untested and will be removed in Matplotlib 3.0. Use the WXAgg backend instead. See Matplotlib usage FAQ for more info on backends. Use WXAgg instead.
warnings.warn(message, mplDeprecation, stacklevel=1)
/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/matplotlib/backends/backend_wx.py:319: wxPyDeprecationWarning: Call to deprecated item. Use DrawText instead.
gfx_ctx.DrawRotatedText(s, x - xo, y - yo, rads)
So it looks like the problem is due to some wx deprecation inside of matplotlib.
Rolf of Saxony's answer also worked for me and did not produce the warnings.