Plot the closed curves of the path.
764077
def plot_discrete(self, show=False, annotations=True):
        
        import matplotlib.pyplot as plt
        axis = plt.axes()
        axis.set_aspect('equal', 'datalim')

        for i, points in enumerate(self.discrete):
            color = ['g', 'k'][i in self.root]
            axis.plot(*points.T, color=color)

        if annotations:
            for e in self.entities:
                if not hasattr(e, 'plot'):
                    continue
                e.plot(self.vertices)

        if show:
            plt.show()
        return axis
933687
private boolean onPath(Shape path, float x, float y) {
		for (int i=0;i<path.getPointCount()+1;i++) {
			int n = rationalPoint(path, i+1);
			Line line = getLine(path, rationalPoint(path, i), n);
			if (line.distance(new Vector2f(x,y)) < EPSILON*100) {
				return true;
			}
		}
		
		return false;
	}
794637
def bezier_curve_approx_len(P=[(0.0, 0.0)]):
    '''
    '''
    assert isinstance(P, list)
    assert len(P) > 0
    for p in P:
        assert isinstance(p, tuple)
        for i in p:
            assert len(p) > 1
            assert isinstance(i, float)
    
    n_seg = len(P) - 1
    pts = pts_on_bezier_curve(P, n_seg)
    return sum([distance_between_pts(pts[i], pts[i+1]) for i in range(n_seg)])
897108
function pathDataToString(path) {
    var str = [];
    var data = path.data;
    var dataLength = path.len();
    for (var i = 0; i < dataLength;) {
        var cmd = data[i++];
        var cmdStr = '';
        var nData = 0;
        switch (cmd) {
            case CMD.M:
                cmdStr = 'M';
                nData = 2;
                break;
            case CMD.L:
                cmdStr = 'L';
                nData = 2;
                break;
            case CMD.Q:
                cmdStr = 'Q';
                nData = 4;
                break;
            case CMD.C:
                cmdStr = 'C';
                nData = 6;
                break;
            case CMD.A:
                var cx = data[i++];
                var cy = data[i++];
                var rx = data[i++];
                var ry = data[i++];
                var theta = data[i++];
                var dTheta = data[i++];
                var psi = data[i++];
                var clockwise = data[i++];

                var dThetaPositive = Math.abs(dTheta);
                var isCircle = isAroundZero(dThetaPositive - PI2)
                    && !isAroundZero(dThetaPositive);

                var large = false;
                if (dThetaPositive >= PI2) {
                    large = true;
                }
                else if (isAroundZero(dThetaPositive)) {
                    large = false;
                }
                else {
                    large = (dTheta > -PI && dTheta < 0 || dTheta > PI)
                        === !!clockwise;
                }

                var x0 = round4(cx + rx * mathCos(theta));
                var y0 = round4(cy + ry * mathSin(theta));

                // It will not draw if start point and end point are exactly the same
                // We need to shift the end point with a small value
                // FIXME A better way to draw circle ?
                if (isCircle) {
                    if (clockwise) {
                        dTheta = PI2 - 1e-4;
                    }
                    else {
                        dTheta = -PI2 + 1e-4;
                    }

                    large = true;

                    if (i === 9) {
                        // Move to (x0, y0) only when CMD.A comes at the
                        // first position of a shape.
                        // For instance, when drawing a ring, CMD.A comes
                        // after CMD.M, so it's unnecessary to move to
                        // (x0, y0).
                        str.push('M', x0, y0);
                    }
                }

                var x = round4(cx + rx * mathCos(theta + dTheta));
                var y = round4(cy + ry * mathSin(theta + dTheta));

                // FIXME Ellipse
                str.push('A', round4(rx), round4(ry),
                    mathRound(psi * degree), +large, +clockwise, x, y);
                break;
            case CMD.Z:
                cmdStr = 'Z';
                break;
            case CMD.R:
                var x = round4(data[i++]);
                var y = round4(data[i++]);
                var w = round4(data[i++]);
                var h = round4(data[i++]);
                str.push(
                    'M', x, y,
                    'L', x + w, y,
                    'L', x + w, y + h,
                    'L', x, y + h,
                    'L', x, y
                );
                break;
        }
        cmdStr && str.push(cmdStr);
        for (var j = 0; j < nData; j++) {
            // PENDING With scale
            str.push(round4(data[i++]));
        }
    }
    return str.join(' ');
}
881448
def curve_evaluate(curve):
    """"""
    if NO_IMAGES:
        return

    ax = curve.plot(256)
    points = curve.evaluate_multi(np.asfortranarray([0.75]))
    ax.plot(
        points[0, :], points[1, :], color="black", linestyle="None", marker="o"
    )
    ax.axis("scaled")
    ax.set_xlim(-0.125, 1.125)
    ax.set_ylim(-0.0625, 0.5625)
    save_image(ax.figure, "curve_evaluate.png")
1181431
def check_on_curve(self):
        """"""
        if not self._curve.contains_point(*self):
            raise NoSuchPointError('({},{}) is not on the curve {}'.format(self[0], self[1], self._curve))
194051
def _plot(self):
        """"""
        for serie in self.series[::-1 if self.stack_from_top else 1]:
            self.line(serie)
        for serie in self.secondary_series[::-1 if self.stack_from_top else 1]:
            self.line(serie, True)
159889
function curve( $x0, $y0, $x1, $y1, $x2, $y2, $x3, $y3 )
    {
        // in the current line style, draw a bezier curve from (x0,y0) to (x3,y3) using the other two points
        // as the control points for the curve.
        $this->objects[$this->currentContents]['c'].="\n".sprintf('%.3F',$x0).' '.sprintf('%.3F',$y0).' m '.sprintf('%.3F',$x1).' '.sprintf('%.3F',$y1);
        $this->objects[$this->currentContents]['c'].= ' '.sprintf('%.3F',$x2).' '.sprintf('%.3F',$y2).' '.sprintf('%.3F',$x3).' '.sprintf('%.3F',$y3).' c S';
    }
438614
def animate_pendulum(self, m,  path="anim_npendulum"):
        

        if os.path.exists(path):
            shutil.rmtree(path)
        os.makedirs(path)

        for t in range(0, 1000, 32):
            ax = axes()
            self.plot_npendulum(ax, m, t)
            savefig(os.path.join(path, "{}.png".format(t)))
            clf()
345958
def plot(self):
        """"""
        plt.plot(self.bin_edges, self.hist, self.bin_edges, self.best_pdf)
47960
function _drawQuadratic(canvas, ctx, params, path) {
	var l,
		lx, ly,
		lcx, lcy;

	l = 2;

	_addStartArrow(
		canvas,
		ctx,
		params,
		path,
		path.cx1 + params.x,
		path.cy1 + params.y,
		path.x1 + params.x,
		path.y1 + params.y
	);

	if (path.x1 !== undefined && path.y1 !== undefined) {
		ctx.moveTo(path.x1 + params.x, path.y1 + params.y);
	}
	while (true) {
		// Calculate next coordinates
		lx = path['x' + l];
		ly = path['y' + l];
		lcx = path['cx' + (l - 1)];
		lcy = path['cy' + (l - 1)];
		// If coordinates are given
		if (lx !== undefined && ly !== undefined && lcx !== undefined && lcy !== undefined) {
			// Draw next curve
			ctx.quadraticCurveTo(lcx + params.x, lcy + params.y, lx + params.x, ly + params.y);
			l += 1;
		} else {
			// Otherwise, stop drawing
			break;
		}
	}
	l -= 1;
	_addEndArrow(
		canvas,
		ctx,
		params,
		path,
		path['cx' + (l - 1)] + params.x,
		path['cy' + (l - 1)] + params.y,
		path['x' + l] + params.x,
		path['y' + l] + params.y
	);
}
278913
def validate_known_curve():
    """"""
    plt.figure()
    N = 100
    x = numpy.linspace(-1, 1, N)
    y = numpy.sin(4 * x)
    smoother.DEFAULT_BASIC_SMOOTHER = smoother.BasicFixedSpanSmootherSlowUpdate
    smooth = smoother.perform_smooth(x, y, smoother_cls=supersmoother.SuperSmoother)
    plt.plot(x, smooth.smooth_result, label='Slow')
    smoother.DEFAULT_BASIC_SMOOTHER = smoother.BasicFixedSpanSmoother
    smooth = smoother.perform_smooth(x, y, smoother_cls=supersmoother.SuperSmoother)
    plt.plot(x, smooth.smooth_result, label='Fast')
    plt.plot(x, y, '.', label='data')
    plt.legend()
    plt.show()
1350834
def plot_final(self, ax):
        '''
        

        '''

        # Plot the light curve
        bnmask = np.array(
            list(set(np.concatenate([self.badmask, self.nanmask]))), dtype=int)

        def M(x): return np.delete(x, bnmask)
        if (self.cadence == 'lc') or (len(self.time) < 4000):
            ax.plot(M(self.time), M(self.flux), ls='none',
                    marker='.', color='k', markersize=2, alpha=0.3)
        else:
            ax.plot(M(self.time), M(self.flux), ls='none', marker='.',
                    color='k', markersize=2, alpha=0.03, zorder=-1)
            ax.set_rasterization_zorder(0)
        # Hack: Plot invisible first and last points to ensure
        # the x axis limits are the
        # same in the other plots, where we also plot outliers!
        ax.plot(self.time[0], np.nanmedian(M(self.flux)), marker='.', alpha=0)
        ax.plot(self.time[-1], np.nanmedian(M(self.flux)), marker='.', alpha=0)

        # Plot the GP (long cadence only)
        if self.cadence == 'lc':
            gp = GP(self.kernel, self.kernel_params, white=False)
            gp.compute(self.apply_mask(self.time),
                       self.apply_mask(self.fraw_err))
            med = np.nanmedian(self.apply_mask(self.flux))
            y, _ = gp.predict(self.apply_mask(self.flux) - med, self.time)
            y += med
            ax.plot(M(self.time), M(y), 'r-', lw=0.5, alpha=0.5)

            # Compute the CDPP of the GP-detrended flux
            self.cdppg = self._mission.CDPP(self.apply_mask(
                self.flux - y + med), cadence=self.cadence)

        else:

            # We're not going to calculate this
            self.cdppg = 0.

        # Appearance
        ax.annotate('Final', xy=(0.98, 0.025), xycoords='axes fraction',
                    ha='right', va='bottom', fontsize=10, alpha=0.5,
                    fontweight='bold')
        ax.margins(0.01, 0.1)

        # Get y lims that bound 99% of the flux
        flux = np.delete(self.flux, bnmask)
        N = int(0.995 * len(flux))
        hi, lo = flux[np.argsort(flux)][[N, -N]]
        fsort = flux[np.argsort(flux)]
        pad = (hi - lo) * 0.1
        ylim = (lo - pad, hi + pad)
        ax.set_ylim(ylim)
        ax.get_yaxis().set_major_formatter(Formatter.Flux)
348547
def draw_path(data, path, draw_options=None, simplify=None):
    
    # 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
172114
def plots_from_files(imspaths, figsize=(10,5), rows=1, titles=None, maintitle=None):
    
    f = plt.figure(figsize=figsize)
    if maintitle is not None: plt.suptitle(maintitle, fontsize=16)
    for i in range(len(imspaths)):
        sp = f.add_subplot(rows, ceildiv(len(imspaths), rows), i+1)
        sp.axis('Off')
        if titles is not None: sp.set_title(titles[i], fontsize=16)
        img = plt.imread(imspaths[i])
        plt.imshow(img)
597556
def plot(self):
		'''
		
		'''
		pl.plot(self.x, self.y, '.')
		pl.plot(self.x_int, self.y_int)
		pl.grid(True)
		pl.show()
14916
def _make_S_curve(x, range=(-0.75, 0.75)):
    """"""
    assert x.ndim == 1
    x = x - x.min()
    theta = 2 * np.pi * (range[0] + (range[1] - range[0]) * x / x.max())
    X = np.empty((x.shape[0], 2), dtype=float)
    X[:, 0] = np.sign(theta) * (1 - np.cos(theta))
    X[:, 1] = np.sin(theta)
    X *= x.max() / (2 * np.pi * (range[1] - range[0]))
    return X