Categories
Python Answers

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

Spread the love

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.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *