pythonmatplotlibtuplesvisualizationmachine-learning-model

How to save the return of viz.visualize_image_attr as image Python


I need to use the return value of

viz.visualize_image_attr(fa_attr_without_max[0].cpu().detach().permute(1, 2, 0).numpy(), sign="all", title="Integrated Gradients")

as an image.

This method returns: 2-element tuple of *figure, **axis*; their data type is matplotlib.pyplot.figure

I tried plt and searched for convert tuple into image but no result found


Solution

  • You should be able to use matplotlib.pyplot.savefig

    from matplotlib import pyplot as plt
    
    example = (x, y) #Assume these are matplotlib figures returned from your func
    example[0].savefig('foo.png')
    example[1].savefig('foo2.pdf')