From f0f6c98ebb5d22d5128803b933384dd010db8bc0 Mon Sep 17 00:00:00 2001 From: Craig Warren Date: Mon, 19 Sep 2016 14:34:56 +0100 Subject: [PATCH] Modified setup of matplotlib for Linux and Windows to force using QT5 backend. Problem is that with conda installed qt5/pyqt5 matplotlib still tries to use qt4 backend. --- gprMax/optimisation_taguchi.py | 5 +++++ tests/benchmarking/plot_benchmark.py | 5 +++++ tests/test_compare_analytical.py | 4 ++++ tests/test_compare_experimental.py | 4 ++++ tests/test_compare_numerical.py | 5 ++++- tools/plot_Ascan.py | 5 +++++ tools/plot_Bscan.py | 5 +++++ tools/plot_antenna_params.py | 5 +++++ tools/plot_source_wave.py | 5 +++++ user_libs/antenna_patterns/initial_save.py | 5 +++++ user_libs/antenna_patterns/plot_fields.py | 5 +++++ user_libs/optimisation_taguchi/fitness_functions.py | 4 ++++ 12 files changed, 56 insertions(+), 1 deletion(-) diff --git a/gprMax/optimisation_taguchi.py b/gprMax/optimisation_taguchi.py index add32eeb..749543a0 100644 --- a/gprMax/optimisation_taguchi.py +++ b/gprMax/optimisation_taguchi.py @@ -21,6 +21,7 @@ import datetime from importlib import import_module import os import pickle +import sys from time import perf_counter from colorama import init, Fore, Style @@ -440,6 +441,10 @@ def plot_optimisation_history(fitnessvalueshist, optparamshist, optparamsinit): optparamshist (dict): Name of parameters to optimise and history of their values """ + import matplotlib + # Make sure QT5 is used if not on Mac OS X + if sys.platform != 'darwin': + matplotlib.use('Qt5Agg') import matplotlib.pyplot as plt # Plot history of fitness values diff --git a/tests/benchmarking/plot_benchmark.py b/tests/benchmarking/plot_benchmark.py index 0419d837..e586b598 100644 --- a/tests/benchmarking/plot_benchmark.py +++ b/tests/benchmarking/plot_benchmark.py @@ -1,7 +1,12 @@ import argparse import os +import sys import numpy as np +import matplotlib +# Make sure QT5 is used if not on Mac OS X +if sys.platform != 'darwin': + matplotlib.use('Qt5Agg') import matplotlib.pyplot as plt import matplotlib.gridspec as gridspec diff --git a/tests/test_compare_analytical.py b/tests/test_compare_analytical.py index 1a74facf..05c0236e 100644 --- a/tests/test_compare_analytical.py +++ b/tests/test_compare_analytical.py @@ -22,6 +22,10 @@ import sys import h5py import numpy as np +import matplotlib +# Make sure QT5 is used if not on Mac OS X +if sys.platform != 'darwin': + matplotlib.use('Qt5Agg') import matplotlib.pyplot as plt import matplotlib.gridspec as gridspec diff --git a/tests/test_compare_experimental.py b/tests/test_compare_experimental.py index 33c40c15..4158a43e 100644 --- a/tests/test_compare_experimental.py +++ b/tests/test_compare_experimental.py @@ -22,6 +22,10 @@ import sys import h5py import numpy as np +import matplotlib +# Make sure QT5 is used if not on Mac OS X +if sys.platform != 'darwin': + matplotlib.use('Qt5Agg') import matplotlib.pyplot as plt from gprMax.exceptions import CmdInputError diff --git a/tests/test_compare_numerical.py b/tests/test_compare_numerical.py index 5d7d5f45..8c5b5d65 100644 --- a/tests/test_compare_numerical.py +++ b/tests/test_compare_numerical.py @@ -21,7 +21,10 @@ import sys import h5py import numpy as np -import matplotlib as mpl +import matplotlib +# Make sure QT5 is used if not on Mac OS X +if sys.platform != 'darwin': + matplotlib.use('Qt5Agg') import matplotlib.pyplot as plt from tools.plot_fields import plot_Ascan diff --git a/tools/plot_Ascan.py b/tools/plot_Ascan.py index 99815713..e883bfa4 100644 --- a/tools/plot_Ascan.py +++ b/tools/plot_Ascan.py @@ -18,9 +18,14 @@ import argparse import os +import sys import h5py import numpy as np +import matplotlib +# Make sure QT5 is used if not on Mac OS X +if sys.platform != 'darwin': + matplotlib.use('Qt5Agg') import matplotlib.pyplot as plt import matplotlib.gridspec as gridspec diff --git a/tools/plot_Bscan.py b/tools/plot_Bscan.py index 267d3771..abb2e1f0 100644 --- a/tools/plot_Bscan.py +++ b/tools/plot_Bscan.py @@ -18,9 +18,14 @@ import argparse import os +import sys import h5py import numpy as np +import matplotlib +# Make sure QT5 is used if not on Mac OS X +if sys.platform != 'darwin': + matplotlib.use('Qt5Agg') import matplotlib.pyplot as plt from gprMax.exceptions import CmdInputError diff --git a/tools/plot_antenna_params.py b/tools/plot_antenna_params.py index 6c1c6077..33128ed5 100644 --- a/tools/plot_antenna_params.py +++ b/tools/plot_antenna_params.py @@ -18,9 +18,14 @@ import argparse import os +import sys import h5py import numpy as np +import matplotlib +# Make sure QT5 is used if not on Mac OS X +if sys.platform != 'darwin': + matplotlib.use('Qt5Agg') import matplotlib.pyplot as plt import matplotlib.gridspec as gridspec diff --git a/tools/plot_source_wave.py b/tools/plot_source_wave.py index b269ce8d..7e631220 100644 --- a/tools/plot_source_wave.py +++ b/tools/plot_source_wave.py @@ -18,8 +18,13 @@ import argparse import os +import sys import numpy as np +import matplotlib +# Make sure QT5 is used if not on Mac OS X +if sys.platform != 'darwin': + matplotlib.use('Qt5Agg') import matplotlib.pyplot as plt from gprMax.exceptions import CmdInputError diff --git a/user_libs/antenna_patterns/initial_save.py b/user_libs/antenna_patterns/initial_save.py index 3bf5a06b..a2aef25f 100644 --- a/user_libs/antenna_patterns/initial_save.py +++ b/user_libs/antenna_patterns/initial_save.py @@ -7,9 +7,14 @@ import argparse import os +import sys import h5py import numpy as np +import matplotlib +# Make sure QT5 is used if not on Mac OS X +if sys.platform != 'darwin': + matplotlib.use('Qt5Agg') import matplotlib.pyplot as plt from gprMax.constants import c, z0 diff --git a/user_libs/antenna_patterns/plot_fields.py b/user_libs/antenna_patterns/plot_fields.py index 30fd7b9e..4ee2318c 100644 --- a/user_libs/antenna_patterns/plot_fields.py +++ b/user_libs/antenna_patterns/plot_fields.py @@ -7,8 +7,13 @@ import argparse import os +import sys import numpy as np +import matplotlib +# Make sure QT5 is used if not on Mac OS X +if sys.platform != 'darwin': + matplotlib.use('Qt5Agg') import matplotlib.pyplot as plt from gprMax.constants import c, z0 diff --git a/user_libs/optimisation_taguchi/fitness_functions.py b/user_libs/optimisation_taguchi/fitness_functions.py index 16735748..a1f58e79 100755 --- a/user_libs/optimisation_taguchi/fitness_functions.py +++ b/user_libs/optimisation_taguchi/fitness_functions.py @@ -9,6 +9,10 @@ import os import sys import h5py +import matplotlib +# Make sure QT5 is used if not on Mac OS X +if sys.platform != 'darwin': + matplotlib.use('Qt5Agg') import matplotlib.pyplot as plt import numpy as np from scipy import signal