code: def test_antiparallel_simplification():
      def _get_simplified(x, y):
          fig, ax = plt.subplots()
          p1 = ax.plot(x, y)
  
          path = p1[0].get_path()
          transform = p1[0].get_transform()
          path = transform.transform_path(path)
          simplified = path.cleaned(simplify=True)
          simplified = transform.inverted().transform_path(simplified)
  
          return simplified
  
      # test ending on a maximum
      x = [0, 0, 0, 0, 0, 1]
      y = [0.5, 1, -1, 1, 2, 0.5]
  
      simplified = _get_simplified(x, y)
  
      assert_array_almost_equal(
          [[0.0, 0.5], [0.0, -1.0], [0.0, 2.0], [1.0, 0.5]],
          simplified.vertices[:-2, :],
      )
  
      # test ending on a minimum
      x = [0, 0, 0, 0, 0, 1]
      y = [0.5, 1, -1, 1, -2, 0.5]
  
      simplified = _get_simplified(x, y)
  
      assert_array_almost_equal(
          [[0.0, 0.5], [0.0, 1.0], [0.0, -2.0], [1.0, 0.5]],
          simplified.vertices[:-2, :],
      )
  
      # test ending in between
      x = [0, 0, 0, 0, 0, 1]
      y = [0.5, 1, -1, 1, 0, 0.5]
  
      simplified = _get_simplified(x, y)
  
      assert_array_almost_equal(
          [[0.0, 0.5], [0.0, 1.0], [0.0, -1.0], [0.0, 0.0], [1.0, 0.5]],
          simplified.vertices[:-2, :],
      )
  
      # test no anti-parallel ending at max
      x = [0, 0, 0, 0, 0, 1]
      y = [0.5, 1, 2, 1, 3, 0.5]
  
      simplified = _get_simplified(x, y)
  
      assert_array_almost_equal(
          [[0.0, 0.5], [0.0, 3.0], [1.0, 0.5]],
          simplified.vertices[:-2, :],
      )
  
      # test no anti-parallel ending in middle
      x = [0, 0, 0, 0, 0, 1]
      y = [0.5, 1, 2, 1, 1, 0.5]
  
      simplified = _get_simplified(x, y)
  
      assert_array_almost_equal(
          [[0.0, 0.5], [0.0, 2.0], [0.0, 1.0], [1.0, 0.5]],
          simplified.vertices[:-2, :],
      )
  
imports: import base64
  import io
  import numpy
  from numpy.testing import assert_array_almost_equal, assert_array_equal
  import pytest
  from matplotlib.testing.decorators import check_figures_equal, image_comparison, remove_ticks_and_titles
  import matplotlib.pyplot
  from matplotlib import patches, transforms
  from matplotlib.path import Path
label_desc: Use image node_id 6 for calling a global function with example usage: test_antiparallel_simplification() and returns: simplified