user11607936
user11607936

Reputation:

Subploting saved png figures- remove axis

I am trying to subplot 4 figures i have already saved before as png.

This is the code i am using:

img1 = mpimg.imread(r'C:\Users\nikos.000\png\kicks_UCS_elec.png')
img2 = mpimg.imread(r'C:\Users\nikos.000\png\DW_UCS_elec.png')

img3 = mpimg.imread(r'C:\Users\nikos.000\png\energ_UCS_elec.png')
img4 = mpimg.imread(r'C:\Users\nikos.000\png\UCS_elec_kinet.png')



f, ax = plt.subplots(2,2)
ax[0,0].imshow(img1)

ax[0,1].imshow(img2)

ax[1,0].imshow(img3)

ax[1,1].imshow(img4)
f.axes.get_xaxis().set_visible(False)
f.axes.get_yaxis().set_visible(False)

And this is the result I am getting:

enter image description here

I want to get rid of the extra axes printed in each subplot. Is this possible?

Upvotes: 0

Views: 73

Answers (1)

gepcel
gepcel

Reputation: 1356

You should turn off each axis. Using your own code for example:

img1 = mpimg.imread(r'C:\Users\nikos.000\vlahos\png\kicks_UCS_elec.png')
img2 = mpimg.imread(r'C:\Users\nikos.000\vlahos\png\DW_UCS_elec.png')

img3 = mpimg.imread(r'C:\Users\nikos.000\vlahos\png\energ_UCS_elec.png')
img4 = mpimg.imread(r'C:\Users\nikos.000\vlahos\png\UCS_elec_kinet.png')



f, ax = plt.subplots(2,2)
ax[0,0].imshow(img1)

ax[0,1].imshow(img2)

ax[1,0].imshow(img3)

ax[1,1].imshow(img4)

for a in ax.flat:
    a.axis('off')

Upvotes: 1

Related Questions