Displaying grid files on screen - problem with context manager

Any comments why image does not show up by using context manager (Case 1) but does show when not using context manager (Case 2)? I would prefer using context manager as it prevents errors where context has been already created and basically you have to comment out line gxp = gxgx.GXpy() in order to be able to run code anew. Or is there a way to test whether context has been created?

Case 1. Using context manager for GXpy: no image shows (but I can see in C:\Users\username\AppData\Local\Temp\GeosoftTemp that there is a new folder which actually contains that image as png file)

import geosoft.gxpy.grid as gxgrid
import geosoft.gxpy.gx as gxgx
from IPython.display import Image

with gxgx.GXpy() as gxp:
image_file = gxgrid.Grid.open('mag_data_mag.grd').image_file(shade=True, pix_width=500)
Image(image_file
)

Case 2. Using no context manager for GXpy: image shows

import geosoft.gxpy.grid as gxgrid
import geosoft.gxpy.gx as gxgx
from IPython.display import Image

gxp = gxgx.GXpy()
image_file = gxgrid.Grid.open('mag_data_mag.grd').image_file(shade=True, pix_width=500)
Image(image_file)