Skip to content

Commit

Permalink
Use headless ("Agg") matplotlib backend in CI (#1133)
Browse files Browse the repository at this point in the history
Fixes #1132

This also drops internal matplotlib.use() calls, leaving the
choice of backend in the hands of the user/environment.
We believe these calls were counterproductive and redundant, given
that, from https://matplotlib.org/stable/users/explain/backends.html

> Without a backend explicitly set, Matplotlib automatically detects a
> usable backend based on what is available on your system

Co-authored-by: Joshua Newton <joshuacwnewton@gmail.com>
  • Loading branch information
kousu and joshuacwnewton committed May 19, 2022
1 parent bd904e5 commit 1da019b
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 16 deletions.
5 changes: 5 additions & 0 deletions .github/workflows/run_tests.yml
Expand Up @@ -19,6 +19,11 @@ env:
# (TravisCI quietly defined this on all their platforms, but we have to give it manually on GithubCI.)
DEBIAN_FRONTEND: 'noninteractive'
HDF5_USE_FILE_LOCKING: 'FALSE'
# Skip to the headless matplotlib renderer, which is less
# bug-prone in the constrained environment of CI
# Tip from a matplotlib dev: https://github.com/spinalcordtoolbox/spinalcordtoolbox/issues/3388#issuecomment-846091012
# Ref: https://matplotlib.org/stable/users/explain/backends.html
MPLBACKEND: 'Agg'

jobs:
ultra_matrix_test:
Expand Down
17 changes: 2 additions & 15 deletions ivadomed/scripts/visualize_and_compare_testing_models.py
Expand Up @@ -9,6 +9,7 @@
###########################################################################################################

import matplotlib
from matplotlib import pyplot as plt
import pandas as pd
import numpy as np
import itertools
Expand All @@ -21,21 +22,7 @@

matplotlib.rcParams['toolbar'] = 'None' # Remove buttons

gui_env = ['TKAgg', 'GTKAgg', 'Qt4Agg', 'WXAgg']
selected_gui_env = []
for gui in gui_env:
try:
matplotlib.use(gui)
from matplotlib import pyplot as plt

selected_gui_env = gui
break
except:
continue
# If none works
if selected_gui_env == []:
from matplotlib import pyplot as plt

if matplotlib.get_backend() == "agg":
logger.warning("No backend can be used - Visualization will fail")
else:
logger.info(f"Using: {matplotlib.get_backend()} gui")
Expand Down
1 change: 0 additions & 1 deletion ivadomed/utils.py
Expand Up @@ -222,7 +222,6 @@ def plot_transformed_sample(before, after, list_title=None, fname_out="", cmap="
if fname_out:
plt.savefig(fname_out)
else:
matplotlib.use('TkAgg')
plt.show()


Expand Down

0 comments on commit 1da019b

Please sign in to comment.