Skip to content
Snippets Groups Projects
Commit 7799b43c authored by Jameson Graef Rollins's avatar Jameson Graef Rollins
Browse files

CLI support systems with no display

matplotlib.pyplot throws a RuntimeError when no display is present.  One
way around that is to set the backend to AGG.  But we don't want AGG when
we do have a display.  So we only want to set it opportunistically.  But
it also has to be set before anything else is imported.  Kind of convoluted.

So we really just import pyplot as opportunistically as possible, and then
rely on setting AGG backend when we're sure we don't need it in main().
parent 0f4c8396
No related branches found
No related tags found
No related merge requests found
......@@ -3,7 +3,6 @@ import os
import signal
import argparse
import numpy as np
from matplotlib import pyplot as plt
from IPython.terminal.embed import InteractiveShellEmbed
import logging
......@@ -136,6 +135,18 @@ def main():
v = float(v)
range_params[p] = v
if args.save:
# FIXME: this silliness seems to be the only way to have
# matplotlib usable on systems without a display. There must
# be a better way. 'AGG' is a backend that works without
# displays. but it has to be set before any other matplotlib
# stuff is imported. and we *don't* want it set if we do want
# to show an interactive plot. there doesn't seem a way to
# set this opportunistically.
import matplotlib
matplotlib.use('AGG')
from matplotlib import pyplot as plt
##########
# main calculations
......
from numpy import sqrt
import matplotlib.pyplot as plt
import logging
PRIORITY_MAP = {
'Quantum Vacuum': 0,
......@@ -80,6 +77,7 @@ def plot_noise(
f = noises['Freq']
if ax is None:
import matplotlib.pyplot as plt
fig = plt.figure()
ax = fig.add_subplot(1, 1, 1)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment