Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to save and then load a seaborn jointplot

I have a seaborn jointplot

fig = sns.jointplot(x=[1,2,3,4],y=[4,3,2,1])

How do I save it and then load it back as an image inside databricks so I can use it in a subplot?

when I try to load the image back in from dbfs using mping.imread it tells me ‘Jointgrid does not have an attribute imread’

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

I was able to get the mentioned sample jointplot to save down and load back in using this code

Saving:

plot = sns.jointplot(x=[1,2,3,4],y=[4,3,2,1])
plot.savefig('/dbfs/FileStore/figure.png')

Loading:

img = plt.imread('/dbfs/FileStore/figure.png')

Displaying:

plt.imshow(img)

Hope this helped!

Edit:
Additionally I know you mentioned making it part of a subplot you can use this code to do that:

f, axarr = plt.subplots(2,1,figsize=(25,16))
axarr[1,1].imshow(mpimg.imread(figname1))
axarr[2,1].imshow(mpimg.imread(figname2))
[ax.set_axis_off() for ax in axarr.ravel()]
plt.tight_layout()
plt.show()
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading