I standardized tests and library code to only try to import matplotlib when plotting is first attempted. Furthermore the library code logs a warning and continues without plotting if the import fails. The unit tests raise an exception because plotting is never the norm and if a user specifies it then they can put up with an exception if something is wrong.
I also standardized on import matplotlib.pyplot as plt, including some older code that used pylab instead of pyplot, and removed a few attempts to set the back end because I think that should be up to the user.
I left the examples unchanged.