Skip to content

Commit

Permalink
Merge pull request #2597 from jtkrogel/nx_mpl_import
Browse files Browse the repository at this point in the history
Nexus: fix matplotlib import in qmca
  • Loading branch information
prckent committed Jul 23, 2020
2 parents 96ccb03 + 773b12a commit da7ea5d
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 29 deletions.
11 changes: 0 additions & 11 deletions nexus/bin/qmc-fit
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,6 @@ except ImportError:
#end try

try:
import matplotlib
gui_envs = ['GTKAgg','TKAgg','Qt4Agg','WXAgg']
for gui in gui_envs:
try:
matplotlib.use(gui,warn=False, force=True)
from matplotlib import pyplot
break
except:
continue
#end try
#end for
import matplotlib.pyplot as plt
params = {'legend.fontsize':14,'figure.facecolor':'white','figure.subplot.hspace':0.,
'axes.labelsize':16,'xtick.labelsize':14,'ytick.labelsize':14}
Expand Down
34 changes: 16 additions & 18 deletions nexus/bin/qmca
Original file line number Diff line number Diff line change
Expand Up @@ -62,31 +62,17 @@ except (ImportError,RuntimeError):


# matplotlib imports
success = False
matplotlib_import_success = False
try:
import matplotlib
gui_envs = ['GTKAgg','TKAgg','Qt4Agg','WXAgg']
for gui in gui_envs:
try:
matplotlib.use(gui,warn=False, force=True)
from matplotlib import pyplot
success = True
break
except:
continue
#end try
#end for
import matplotlib.pyplot as plt

params = {'legend.fontsize':14,'figure.facecolor':'white','figure.subplot.hspace':0.,
'axes.labelsize':16,'xtick.labelsize':14,'ytick.labelsize':14}
plt.rcParams.update(params)
matplotlib_import_success = True
except (ImportError,RuntimeError):
success = False
matplotlib_import_success = False
#end try
if not success:
plt = unavailable('matplotlib.pyplot')
#end if



Expand Down Expand Up @@ -210,6 +196,13 @@ class QBase(DevBase):
pad = n*' '
self._logfile.write(pad+text.replace('\n','\n'+pad)+'\n')
#end def log


def check_matplotlib_import(self):
if not self.options.nowarn and not matplotlib_import_success:
self.warn('Python library matplotlib raised uncaught exceptions during import. Plots may or may not work.')
#end if
#end def check_matplotlib_import
#end class QBase


Expand Down Expand Up @@ -679,6 +672,7 @@ class DatAnalyzer(QBase):


def plot_trace(self,quantity,style,prefix,shift):
self.check_matplotlib_import()
if not quantity in self.data:
self.error('quantity '+quantity+' is not present in the data for {0}'.format(self.info.filepath),'QMCA')
#end if
Expand Down Expand Up @@ -946,6 +940,10 @@ QMCA examples:
default=None,
help='Sets the floating point precision of displayed statistical results. Must be a floating point format string such as 16.8f, 8.6e, or similar (default=%default).'
)
parser.add_option('--nowarn',dest='nowarn',
action='store_true',default=False,
help='Suppress warning messages (default=%default).'
)

unsupported = set('histogram image reblock report'.split())

Expand Down Expand Up @@ -1291,6 +1289,7 @@ QMCA examples:
#end for
#end if
if plots:
self.check_matplotlib_import()
color = 'b'
line = '-'
marker = '.'
Expand Down Expand Up @@ -1419,7 +1418,6 @@ QMCA examples:
plt.show()
#end if
#end def analyze_data

#end class QMCA


Expand Down

0 comments on commit da7ea5d

Please sign in to comment.