code: def _compare_image_json(baseline, fig, tol=0.001):
      """This function compares the two JSON dictionaries within some tolerance"""
  
      def is_coords(path_element):
          if "," not in path_element:
              return False
          coords = path_element.split(",")
          for coord in coords:
              try:
                  float(coord)
              except ValueError:
                  return False
          return True
  
      def same_coords(path_elem1, path_elem2, tol):
          coords1 = [float(x) for x in path_elem1.split(",")]
          coords2 = [float(x) for x in path_elem2.split(",")]
          for coord1, coord2 in zip(coords1, coords2):
              if abs(coord1 - coord2) > tol:
                  return False
          return True
  
      # Fig has two keys, 'data' and 'layout'
      figd = fig.to_dict()
      # 'data' has a list of dots and lines. The order is required to match
      if len(baseline["data"]) != len(figd["data"]):
          return False
      for stroke1, stroke2 in zip(baseline["data"], figd["data"]):
          # Some properties are strings, no tolerance
          for prop in ["fillcolor", "mode", "type"]:
              if (prop in stroke1) != (prop in stroke2):
                  return False
              if prop not in stroke1:
                  continue
              if stroke1[prop] != stroke2[prop]:
                  return False
  
          # Other properties are numeric, recast as float and use tolerance
          for prop in ["x", "y"]:
              if (prop in stroke1) != (prop in stroke2):
                  return False
              if prop not in stroke1:
                  continue
              if len(stroke1[prop]) != len(stroke2[prop]):
                  return False
              for prop_elem1, prop_elem2 in zip(
                  stroke1[prop], stroke2[prop]
              ):
                  if abs(float(prop_elem1) - float(prop_elem2)) > tol:
                      return False
  
      # 'layout' has a dict of various things, some of which should be identical
      if sorted(baseline["layout"].keys()) != sorted(
          figd["layout"].keys()
      ):
          return False
      if baseline["layout"]["xaxis"] != baseline["layout"]["xaxis"]:
          return False
      if baseline["layout"]["yaxis"] != baseline["layout"]["yaxis"]:
          return False
      # 'shapes' is a list of shape, should be the same up to tolerance
      if "shapes" not in baseline["layout"]:
          baseline["layout"]["shapes"] = []
      if "shapes" not in figd["layout"]:
          figd["layout"]["shapes"] = []
      if len(baseline["layout"]["shapes"]) != len(
          figd["layout"]["shapes"]
      ):
          return False
      for shape1, shape2 in zip(
          baseline["layout"]["shapes"], figd["layout"]["shapes"]
      ):
          if sorted(shape1.keys()) != sorted(shape2.keys()):
              return False
          if shape1["type"] != shape2["type"]:
              return False
          if "line" in shape1:
              if shape1["line"]["color"] != shape2["line"]["color"]:
                  return False
              if ("width" in shape1["line"]) != (
                  "width" in shape2["line"]
              ):
                  return False
              if "width" in shape1["line"]:
                  w1 = float(shape1["line"]["width"])
                  w2 = float(shape2["line"]["width"])
                  if abs(w1 - w2) > tol:
                      return False
  
          if "path" in shape1:
              # SVG path
              path1, path2 = (
                  shape1["path"].split(),
                  shape2["path"].split(),
              )
              if len(path1) != len(path2):
                  return False
              for path_elem1, path_elem2 in zip(path1, path2):
                  is_coords1 = is_coords(path_elem1)
                  is_coords2 = is_coords(path_elem2)
                  if is_coords1 != is_coords2:
                      return False
                  if is_coords1:
                      if not same_coords(path_elem1, path_elem2, tol):
                          return False
  
      # 'layout': skipping that for now, seems mostly plotly internals
  
      return True
  
file_path: python-igraph/tests/drawing/plotly/utils.py
imports: from pathlib import Path
  import sys
  import inspect
  import functools
label_desc: Use image node_id 6 for calling a global function with example usage: _compare_image_json(baseline, fig, tol) and returns: True, True, True, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False