Adds code for drawing an ordinary path in PGFPlots (TikZ).

def draw_path(data, path, draw_options=None, simplify=None):
    """Adds code for drawing an ordinary path in PGFPlots (TikZ).
    """
    # For some reasons, matplotlib sometimes adds void paths which consist of
    # only one point and have 0 fill opacity. To not let those clutter the
    # output TeX file, bail out here.
    if (
        len(path.vertices) == 2
        and all(path.vertices[0] == path.vertices[1])
        and "fill opacity=0" in draw_options
    ):
        return data, "", None, False

    nodes = []
    ff = data["float format"]
    prev = None
    for vert, code in path.iter_segments(simplify=simplify):
        # nschloe, Oct 2, 2015:
        #   The transform call yields warnings and it is unclear why. Perhaps
        #   the input data is not suitable? Anyhow, this should not happen.
        #   Comment out for now.
        # vert = numpy.asarray(
        #         _transform_to_data_coordinates(obj, [vert[0]], [vert[1]])
        #         )
        # For path codes see: http://matplotlib.org/api/path_api.html
        #
        # if code == mpl.path.Path.STOP: pass
        is_area = False
        if code == mpl.path.Path.MOVETO:
            nodes.append(("(axis cs:" + ff + "," + ff + ")").format(*vert))
        elif code == mpl.path.Path.LINETO:
            nodes.append(("--(axis cs:" + ff + "," + ff + ")").format(*vert))
        elif code == mpl.path.Path.CURVE3:
            # Quadratic Bezier curves aren't natively supported in TikZ, but
            # can be emulated as cubic Beziers.
            # From
            # http://www.latex-community.org/forum/viewtopic.php?t=4424&f=45:
            # If you really need a quadratic Bézier curve on the points P0, P1
            # and P2, then a process called 'degree elevation' yields the cubic
            # control points (Q0, Q1, Q2 and Q3) as follows:
            #   CODE: SELECT ALL
            #   Q0 = P0
            #   Q1 = 1/3 P0 + 2/3 P1
            #   Q2 = 2/3 P1 + 1/3 P2
            #   Q3 = P2
            #
            # P0 is the point of the previous step which is needed to compute
            # Q1.
            #
            # Cannot draw quadratic Bezier curves as the beginning of of a path
            assert prev is not None
            Q1 = 1.0 / 3.0 * prev + 2.0 / 3.0 * vert[0:2]
            Q2 = 2.0 / 3.0 * vert[0:2] + 1.0 / 3.0 * vert[2:4]
            Q3 = vert[2:4]
            nodes.append(
                (
                    ".. controls (axis cs:"
                    + ff
                    + ","
                    + ff
                    + ") "
                    + "and (axis cs:"
                    + ff
                    + ","
                    + ff
                    + ") "
                    + ".. (axis cs:"
                    + ff
                    + ","
                    + ff
                    + ")"
                ).format(Q1[0], Q1[1], Q2[0], Q2[1], Q3[0], Q3[1])
            )
        elif code == mpl.path.Path.CURVE4:
            # Cubic Bezier curves.
            nodes.append(
                (
                    ".. controls (axis cs:"
                    + ff
                    + ","
                    + ff
                    + ") "
                    + "and (axis cs:"
                    + ff
                    + ","
                    + ff
                    + ") "
                    + ".. (axis cs:"
                    + ff
                    + ","
                    + ff
                    + ")"
                ).format(*vert)
            )
        else:
            assert code == mpl.path.Path.CLOSEPOLY
            nodes.append("--cycle")
            is_area = True

        # Store the previous point for quadratic Beziers.
        prev = vert[0:2]

    do = "[{}]".format(", ".join(draw_options)) if draw_options else ""
    path_command = "\\path {}\n{};\n".format(do, "\n".join(nodes))

    return data, path_command, draw_options, is_area