3

This is not in a jupyter notebook so this is not a duplicate of this question, but my code is:

from gluoncv import model_zoo, data, utils
from matplotlib import pyplot as plt

...
plt.show()

The error I'm getting is:

/figure.py:445: UserWarning: Matplotlib is currently using ps, which is a non-GUI backend, so cannot show the figure.
  % get_backend())

I created a repl at https://repl.it/@shamoons/WelloffHarmfulMineral

If it matters, I'm using OS X. What do I need to do to get the image to show?

Shamoon
  • 41,293
  • 91
  • 306
  • 570
  • 1
    The `PS` backend is intended for creating PostScript files, not displaying graphs. That warning is `matplotlib` telling you that your call to `plt.show()` won't do what you think it'll do. – yorodm Jan 22 '19 at 19:45

2 Answers2

5

You can use

matplotlib.use("TkAgg")

instead of

matplotlib.use("PS")

when developing on MacOS.

Please note that the import should be before importing plt, like this:

import matplotlib
matplotlib.use('TkAgg')
from matplotlib import pyplot as plt
philshem
  • 24,761
  • 8
  • 61
  • 127
4

matplotlib.use('PS') and plt.show() are mutually exclusive. You need to decide:

  • Do you want to show the figure on screen? Solution: Remove the line matplotlib.use('PS').
  • Do you want to use the PS backend? This seems unlikely, because there is rarely a reason to set the backend to something non-interactive unless working on a server. Anyways, solution: Replace plt.show() by plt.savefig("filname.ps").
ImportanceOfBeingErnest
  • 321,279
  • 53
  • 665
  • 712