Search code examples
pythonmatplotlibfigure

Create plot and display it later without save it with Python


I stocked images in a dict like this and I would like to display them later but I don't know how to do. For now I do this :

for k in dataT:
    fig,ax=plt.subplots(figsize=(12,9))
    f_k=dataT.plot.scatter(x=xcol,y=ycol,c=k,cmap=rainbow,ax=ax)
    Figure_saving[str(k)]=f_k
    plt.close()

And then I would like call a figure at place k in my dict and display it, I try a lot and stuff but specially this and it doesn't work :

plt.show(Figure_saving[k])

Does someone have an idea? Thanks,


Solution

  • To create a plot and display it later I would be making it in its own function.

    Example:

    def createPlot():
       for k in dataT:
        fig,ax=plt.subplots(figsize=(12,9))
        f_k=dataT.plot.scatter(x=xcol,y=ycol,c=k,cmap=rainbow,ax=ax)
        Figure_saving[str(k)]=f_k
        plt.close()
    

    This way you can display the graph every time you call the function.