Skip to content

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

@mjheid

Description

@mjheid

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions