[Python] KeyError when using sc.pl.spatial in Scanpy: 'images' not found in spatial data

Discussão em 'Python' iniciado por Stack, Janeiro 29, 2025.

  1. Stack

    Stack Membro Participativo

    I'm currently working with spatial data analysis using Scanpy and trying to visualize my data using the sc.pl.spatial function. However, I encountered a KeyError when attempting to specify the library_id parameter as 'images'. Here's the code snippet that I'm using:

    import matplotlib.pyplot as plt
    import scanpy as sc

    plt.rcParams["figure.figsize"] = (8, 8)
    sc.pl.spatial(adata, img_key="hires", color=["total_counts", "n_genes_by_counts"], library_id='images')


    KeyError: 'images'


    I understand that this error occurs because the 'images' key is not found in the spatial data. However, I'm unsure why this key is missing or how to resolve this issue.

    Here's what I've tried so far:

    Checked the contents of adata.uns to confirm that 'images' is indeed present. Verified that the data I'm working with contains spatial information and images. Double-checked the documentation for sc.pl.spatial and adata.uns to ensure I'm using the correct parameters. Could someone please help me understand why this KeyError is occurring and how I can resolve it? Any insights or suggestions would be greatly appreciated. Thank you!

    Continue reading...

Compartilhe esta Página