Menu Close

How to generate a PNG with matplotlib when the DISPLAY environment variable is undefined?

Sometimes, we want to generate a PNG with matplotlib when the DISPLAY environment variable is undefined.

In this article, we’ll look at how to generate a PNG with matplotlib when the DISPLAY environment variable is undefined.

How to generate a PNG with matplotlib when the DISPLAY environment variable is undefined?

To generate a PNG with matplotlib when the DISPLAY environment variable is undefined, we can call the matpolotlib method.

For instance, we write

import matplotlib

matplotlib.use('Agg')

to call matplotlib.use to make matplotlib use a different display back end than the default X-Window back end.

Conclusion

To generate a PNG with matplotlib when the DISPLAY environment variable is undefined, we can call the matpolotlib method.

Posted in Python, Python Answers