0

I'm trying to save some figures in a script that is running on a distant server, so without a display. I saw here that using the Agg backend would allow me to create and save figures without displaying them, but when I use this I get this error: File "myscript.py", line 252, in <module> ax1.plot(c_history, label='crit') AttributeError: 'NoneType' object has no attribute 'plot'

Here is the code that creates the error:

fig1 = pyplot.figure()
ax1 = fig1.add_subplot()
ax1.plot(c_history, label='crit')
ax1.plot(g_history, label='gen')
ax1.legend()
if fpath :
    fig1.savefig(out_dir + "wgan_loss.png", bbox_inches="tight")
    pyplot.close(fig1)
else :
    fig1.show()

So I'm guessing the ax1 = fig1.add_subplot() fails to create an axis. The code works fine on my PC in a JupyterLab notebook without the Agg backend.

How can I solve this? Is there a better way to disable plot display?

Whitehot
  • 367
  • 3
  • 15

0 Answers0