简体   繁体   English

我怎样才能正确地 plot 子图?

[英]how can i plot the subplots correctly?

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? output 是没有任何图像的空尺寸,问题是什么?

As @cheersmate says in the comments, you'll want to plot onto axes not ax (which is not defined in your code).正如@cheersmate 在评论中所说,您需要将 plot 放到axes而不是ax (您的代码中未定义)。 axes will be a list containing two Axes objects, so you could instead do: axes将是一个包含两个Axes对象的列表,因此您可以改为:

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()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM