import os
import numpy as np

# Check if $DISPLAY is set (for handling plotting on remote machines with no X-forwarding)
import matplotlib
HAS_DISPLAY = True
try:
    from tkinter import TclError
except:
    HAS_DISPLAY = False

if 'DISPLAY' in os.environ.keys() and HAS_DISPLAY:
    try:
        import pylab as plt
    except TclError:
        HAS_DISPLAY = False

if not HAS_DISPLAY:
    matplotlib.use('Agg')
    import pylab as plt

from matplotlib.ticker import NullFormatter

plt.rcParams['axes.formatter.useoffset'] = False


MAX_PLT_POINTS      = 65536                  # Max number of points in matplotlib plot
MAX_IMSHOW_POINTS   = (8192, 4096)           # Max number of points in imshow plot
@@ -135,97 +135,8 @@
 tlib
-%0AHAS_DISPLAY = True%0Atry:%0A    from tkinter import TclError%0Aexcept:%0A    HAS_DISPLAY = False
 %0A%0Aif
@@ -170,39 +170,10 @@
 ys()
- and HAS_DISPLAY:%0A    try
 :%0A
-    
     
@@ -196,76 +196,12 @@
 plt%0A
-    except TclError:%0A        HAS_DISPLAY = False%0A%0Aif not HAS_DISPLAY
+else
 :%0A  

Change to pylab startup config