MPCPy
MPCPy copied to clipboard
Running MPCPy with plots in docker without display
This issue is to address an issue which appears when running MPCPy in a docker container. When MPCPy tries to validate some parameter estimation runs, it uses matplotlib to create plots. This step requires a display which is by default not enabled in docker. A solution is to switch the backend of matplotlib so it doesn't need a display.
As proposed in https://github.com/lbl-srg/MPCPy/pull/142, plt.switch_backend('agg')
can be used to keep any plotting in the background and not interactive, which will work in Docker. However, this is not a solution to code in MPCPy since it will affect the user's environment without knowledge.
A solution to this is to change the backend of matplotlib in the script running inside of a docker before importing MPCPy classes. For example:
import matplotlib
matplotlib.use('Agg')
from mpcpy import models
# continue code ...