docstr: Converts matplotlib figure object to PIL Image for easier logging. Writing to buffer is necessary
  to avoid wandb cutting our labels off. Wandb autoconvert doesn't pass the `bbox_inches` parameter so we need
  to do this manually.
docstr_tok: ["Converts","matplotlib","figure","object","to","PIL","Image","for","easier","logging",".","Writing","to","buffer","is","necessary","to","avoid","wandb","cutting","our","labels","off",".","Wandb","autoconvert","does","n't","pass","the","`","bbox_inches","`","parameter","so","we","need","to","do","this","manually","."]
code: def _fig2img(self, fig):
      # TODO: start using fi2img from icevision utils
      """Converts matplotlib figure object to PIL Image for easier logging. Writing to buffer is necessary
      to avoid wandb cutting our labels off. Wandb autoconvert doesn't pass the `bbox_inches` parameter so we need
      to do this manually."""
      buf = io.BytesIO()
      fig.savefig(buf, bbox_inches="tight")
      buf.seek(0)
      return PIL.Image.open(buf)
  
file_path: icevision/icevision/metrics/confusion_matrix/confusion_matrix.py
imports: from icevision.data.prediction import Prediction
  from icevision.metrics.metric import Metric
  from icevision.imports import *
  from icevision.metrics.confusion_matrix.confusion_matrix_utils import *
  import PIL
label_desc: Use image node_id 6 for calling the SimpleConfusionMatrix obj's underlying member method code with example usage: obj._fig2img(fig) and returns: PIL