in realbook/callbacks/spectrogram_visualization.py [0:0]
def plot_to_image(figure: plt.figure) -> tf.Tensor:
"""Converts the matplotlib plot specified by 'figure' to a PNG image and
returns it. The supplied figure is closed and inaccessible after this call."""
buf = io.BytesIO()
plt.savefig(buf, format="png")
plt.close(figure)
buf.seek(0)
return tf.expand_dims(tf.image.decode_png(buf.getvalue(), channels=4), 0)