spatialdata-plot icon indicating copy to clipboard operation
spatialdata-plot copied to clipboard

.pl.show() executes plt.show() even when not wanted

Open mjheid opened this issue 2 months ago • 0 comments

When executing a script .pl.show() can execute plt.show() even when not wanted. This is because of these lines, and can be be fixed on the user side through:

import sys
if not hasattr(sys, 'ps1'):
    sys.ps1 = True

To recreate the problem run a python file containing the following code, created tmp.png will be blank:

import spatialdata as sd
import spatialdata_plot
import matplotlib.pyplot as plt

sdata = sd.datasets.blobs()

fig, axs = plt.subplots(ncols=2)

axs[0].plot([1, 2, 3, 4], [1, 2, 3, 4])
sdata.pl.render_images('blobs_image').pl.show(ax=axs[1])
plt.savefig('test.png')

The behavior is unexpected for me, I think including an show: Optional[bool]=None argument and changing the if statement to

if (not hasattr(sys, "ps1") and show is None) or show == True
    plt.show()

would allow for more control. Not sure if it is wanted behavior however?

mjheid avatar Sep 26 '25 13:09 mjheid