I cant show my plot function outputs in Anvil

What I’m trying to do:i want to show my function output (10 images of people) in anvil

What I’ve tried and what’s not working: i tried self.image_2.source = anvil.server.call…

but doesnt show anything in app and sometimes raise error like <matplotlib.figure.figue is object >and so on. plz help me

Code Sample:

# code snippet
def plot_results(k,final_image,train_feed,y_final,y_train,dist,a):
  def add_subplot_border(ax, width=0, color=None):
    fig = ax.get_figure()

    # Convert bottom-left and top-right to display coordinates
    x0, y0 = ax.transAxes.transform((0, 0))
    x1, y1 = ax.transAxes.transform((1, 1))

    # Adjust margins
    x0 -= width
    x1 += width
    y0 -= width
    y1 += width

    # Convert back to Axes coordinates
    x0, y0 = ax.transAxes.inverted().transform((x0, y0))
    x1, y1 = ax.transAxes.inverted().transform((x1, y1))

    rect = plt.Rectangle((x0, y0), x1-x0, y1-y0,
                         color=color,
                         transform=ax.transAxes,
                         zorder=-1)

    fig.patches.append(rect)
# ***************************************************************   
  fig = plt.figure(figsize=(20,20))
  ax = fig.subplots(1,12)
  for i in range(11):
    if k.count(i) == 0:
      ax[i].get_xaxis().set_visible(False)
      ax[i].get_yaxis().set_visible(False)
      ax[i].set_title("NO")
      ax[i].imshow(train_feed[dist.index(a[i])])
    else:
      ax[i].get_xaxis().set_visible(False)
      ax[i].get_yaxis().set_visible(False)
      ax[i].set_title("Yes")
      add_subplot_border(ax[i],width=4,color='Red')
      ax[i].imshow(train_feed[dist.index(a[i])])
  ax[11].get_xaxis().set_visible(False)
  ax[11].get_yaxis().set_visible(False)
  ax[11].set_title(y_final)
  add_subplot_border(ax[11],width=4,color='Yellow')
  ax[11].imshow(final_image)
  # for i in range(len(y_train)):
  #   if (y_train.tolist()[dist.index(a[i])] == y_final) and (i <= 10):
  #     print("AI could find {}".format(dist.index(a[i])))
  #     print(i, y_train.tolist()[dist.index(a[i])] , a[i])
  plt.savefig('/content/abc.png')
  files.download('/content/abc.png')
  plt.close(fig)
  # plt.show('/content/abc.png')
  return anvil.mpl_util.plot_image()

Clone link:
share a copy of your app

from ._anvil_designer import Form1Template
from anvil import *
import anvil.server

class Form1(Form1Template):

  def __init__(self, **properties):
    # Set Form properties and Data Bindings.
    self.init_components(**properties)

       
    

    # Any code you write here will run when the form opens.

  def file_loader_1_change(self, file, **event_args):
    """This method is called when a new file is loaded into this FileLoader"""
    self.image_1.source = file
    print(f"The file's name is: {file.name}")
    self.label_2.text = file.name
     
#   import anvil.mpl_util
  
  def primary_color_1_click(self, **event_args):
    """This method is called when the button is clicked"""
    recognize = anvil.server.call('total',
                                 self.label_2.text)