1

How do I save a plot as a data artifact in MetaFlow? Plotting libraries usually have you write out to a file on disk. How do I view the figure afterwards?

crypdick
  • 16,152
  • 7
  • 51
  • 74

1 Answers1

1

The trick is to serialize the figure's bytes as an artifact:

    from io import BytesIO

    buf = BytesIO()
    fig.savefig(buf)
    self.plot = buf.getvalue()

Then, you can fetch the artifact from the run object and directly use the bytes to plot:

from IPython.display import Image

Image(data=run.data.plot)

Source: https://github.com/outerbounds/dsbook/blob/main/chapter-6/forecast1.py#L21 and @ville on MetaFlow's slack

crypdick
  • 16,152
  • 7
  • 51
  • 74