code: def plot_to_image(figure):
      """Converts the matplotlib plot specified by 'figure' to a PNG image and
      returns it. The supplied figure is closed and inaccessible after this call.
      """
      # Save the plot to a PNG in memory.
      buf = io.BytesIO()
      plt.savefig(buf, format="png")
      # Closing the figure prevents it from being displayed directly inside
      # the notebook.
      plt.close(figure)
      buf.seek(0)
      # Convert PNG buffer to TF image
      image = tf.image.decode_png(buf.getvalue(), channels=4)
      # Add the batch dimension
      image = tf.expand_dims(image, 0)
      return image
  
file_path: guildai/examples/tensorboard/images.py
imports: import os
  from datetime import datetime
  import io
  import itertools
  from packaging import version
  import tensorflow
  from tensorflow import keras
  import matplotlib.pyplot
  import numpy
  import sklearn.metrics
label_desc: Use image node_id 1 for calling a global function with example usage: plot_to_image(figure) and returns: image