1

I don't understand the python syntax where you can have mutliple variable names before the assignment. The line I am referring to is a, ax = plt.subplots(2, 2). Eventhough a is never mentioned ever again, the code doesn't work when I delete a. Does the subplots function somehow refer to a and why is it important?

from skimage.io import imread
import matplotlib.pyplot as plt

# Original
img = imread('catG.png')
# Invert
img_inv = 255 - img
# Mirrored
img_mirr = img[:,::-1]
# Crop
img_cat = img[30:280,200:550]

plt.close('all')
a, ax = plt.subplots(2, 2)

ax[0, 0].imshow(img, cmap='Greys_r')
ax[0, 0].set_title('Original')

ax[0, 1].imshow(img_inv, cmap='Greys_r')
ax[0, 1].set_title('Inverted')

ax[1, 0].imshow(img_mirr, cmap='Greys_r')
ax[1, 0].set_title('Mirrored')

ax[1, 1].imshow(img_cat, cmap='Greys_r')
ax[1, 1].set_title('Cropped')

plt.show()
marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Paul Erlenmeyer
  • 523
  • 2
  • 6
  • 29
  • 1
    Use `_` as name of variable you want to ignore. – Olvin Roght Sep 20 '19 at 16:51
  • `a` is a figure in your case. Best call it `figure` or `fig` to know what it denotes. Only because you don't use it anywhere in the rest of the code, doesn't mean you *couldn't* if you wanted to. Also, you could of course not expand the return tuple of `subplots`, `figax = plt.subplots(2,2)` and later plot to the axes via `figax[1][0,0].plot(...)`. – ImportanceOfBeingErnest Sep 20 '19 at 16:53

0 Answers0