MPCPy icon indicating copy to clipboard operation
MPCPy copied to clipboard

Running MPCPy with plots in docker without display

Open tsnouidui opened this issue 6 years ago • 2 comments

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.

tsnouidui avatar Jun 13 '18 00:06 tsnouidui

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.

dhblum avatar Jun 13 '18 21:06 dhblum

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 ...

dhblum avatar Jan 08 '19 15:01 dhblum