code: def fig_summary(tag, fig, step):
      """Writes an image summary from a string buffer of an mpl figure.
  
      This writer writes a scalar summary in V1 format using V2 API.
  
      Args:
        tag: An arbitrary tag name for this summary.
        fig: A matplotlib figure.
        step: The `int64` monotonic step variable, which defaults
          to `tf.compat.v1.train.get_global_step`.
      """
      buffer = io.BytesIO()
      fig.savefig(buffer, format="png")
      image_summary = tf.compat.v1.Summary.Image(
          encoded_image_string=buffer.getvalue()
      )
      plt.close(fig)
  
      pb = tf.compat.v1.Summary()
      pb.value.add(tag=tag, image=image_summary)
      serialized = tf.convert_to_tensor(pb.SerializeToString())
      tf.summary.experimental.write_raw_pb(
          serialized, step=step, name=tag
      )
  
imports: import io
  import ddsp
  from ddsp.core import tf_float32
  from ddsp.training.plotting import pianoroll_plot_setup
  import matplotlib.patches
  import matplotlib.pyplot
  from matplotlib.ticker import MaxNLocator
  import note_seq
  from note_seq import sequences_lib
  import numpy
  import tensorflow.compat.v2
label_desc: Use image node_id 1 for calling a global function with example usage: fig_summary(tag, fig, step) without return types