Home > Software design >  how can i plot the subplots correctly?
how can i plot the subplots correctly?

Time:01-14

def plot_XAI2(img, model):
  fig, axes = plt.subplots(1, 2, figsize=(12, 6))
  ax.imshow(img)
  ax.imshow(explain_image_lime(img, model))
  ax.set_title("Grad-CAM")
  ax.set_title("LIME")
  plt.show()

img = path_to_image('Lung_cancer (1).jpg')
plot_XAI2(img, model)
predict_image_class(img, model)

The output was empty dimensions without any images, what is the problem?

CodePudding user response:

As @cheersmate says in the comments, you'll want to plot onto axes not ax (which is not defined in your code). axes will be a list containing two Axes objects, so you could instead do:

def plot_XAI2(img, model):
  fig, axes = plt.subplots(1, 2, figsize=(12, 6))
  axes[0].imshow(img)  # plot in first subplot
  axes[1].imshow(explain_image_lime(img, model))  # plot in second subplot
  axes[0].set_title("Grad-CAM")
  axes[1].set_title("LIME")
  plt.show()
  • Related