ij.gui.Plot Java Examples

The following examples show how to use ij.gui.Plot. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Lab.java    From DeconvolutionLab2 with GNU General Public License v3.0 6 votes vote down vote up
public static void plotProfile(RealSignal signal, String name, int x1, int y1, int z1, int x2, int y2, int z2) {
	if (signal == null) {
		return;
	}
	double dx = x2 - x1;
	double dy = y2 - y1;
	double dz = z2 - z1;
	double len = Math.sqrt(dx * dx + dy * dy + dz * dz);
	int n = (int) Math.round(len * 2);
	double ds = len / n;
	dx = (double) (x2 - x1) / n;
	dy = (double) (y2 - y1) / n;
	dz = (double) (z2 - z1) / n;
	double value[] = new double[n];
	double dist[] = new double[n];
	for (int s = 0; s < n; s++) {
		double x = x1 + s * dx;
		double y = y1 + s * dy;
		double z = z1 + s * dz;
		dist[s] = s * ds;
		value[s] = signal.getInterpolatedPixel(x, y, z);
	}
	Plot plot = new Plot(name, "distance", "intensity", dist, value);
	plot.show();
}
 
Example #2
Source File: Compare.java    From TrakEM2 with GNU General Public License v3.0 6 votes vote down vote up
static public Plot makePlot(final CATAParameters cp, final String name, final VectorString3D c) {
	final double[] stdDev = c.getStdDevAtEachPoint();
	if (null == stdDev) return null;
	final double[] index = new double[stdDev.length];
	for (int i=0; i<index.length; i++) index[i] = i;
	Utils.log2("name is " + name);
	Utils.log2("c is " + c);
	Utils.log2("cp is " + cp);
	Utils.log2("stdDev is " + stdDev);
	Utils.log2("c.getCalibrationCopy() is " + c.getCalibrationCopy());
	Utils.log2("c.getDelta() is " + c.getDelta());
	final Calibration cal = c.getCalibrationCopy();
	if (null == cal) Utils.log2("WARNING null calibration!");
	final Plot plot = new Plot(name, name + " -- Point index (delta: " + Utils.cutNumber(c.getDelta(), 2) + " " + (null == cal ? "pixels" : cal.getUnits()) + ")", "Std Dev", index, stdDev);
	plot.setLimits(0, cp.plot_max_x, 0, cp.plot_max_y);
	plot.setSize(cp.plot_width, cp.plot_height);
	plot.setLineWidth(2);
	return plot;
}
 
Example #3
Source File: AbstractCalibrationProcess.java    From thunderstorm with GNU General Public License v3.0 5 votes vote down vote up
protected static void drawSigmaPlots(Plot plot, double[] xVals, SigmaPlotConfig cfg) {
    // add points
    plot.setColor(cfg.allSigma1sColor);
    plot.addPoints(cfg.allFrames, cfg.allSigma1s, Plot.CROSS);
    plot.setColor(cfg.allSigma2sColor);
    plot.addPoints(cfg.allFrames, cfg.allSigma2s, Plot.CROSS);

    // add polynomials
    for(int i = 0; i < cfg.allPolynomsS1.size(); i++) {
        double[] sigma1Vals = new double[xVals.length];
        double[] sigma2Vals = new double[xVals.length];
        for(int j = 0; j < sigma1Vals.length; j++) {
            sigma1Vals[j] = cfg.allPolynomsS1.get(i).value(xVals[j]);
            sigma2Vals[j] = cfg.allPolynomsS2.get(i).value(xVals[j]);
        }
        plot.setColor(cfg.allPolynomsS1Color);
        plot.addPoints(xVals, sigma1Vals, Plot.LINE);
        plot.setColor(cfg.allPolynomsS2Color);
        plot.addPoints(xVals, sigma2Vals, Plot.LINE);
    }

    // add final fitted curves
    double[] sigma1ValsAll = new double[xVals.length];
    double[] sigma2ValsAll = new double[xVals.length];
    for(int j = 0; j < sigma1ValsAll.length; j++) {
        sigma1ValsAll[j] = cfg.polynomS1Final.value(xVals[j]);
        sigma2ValsAll[j] = cfg.polynomS2Final.value(xVals[j]);
    }
    plot.setColor(cfg.polynomS1FinalColor);
    plot.addPoints(xVals, sigma1ValsAll, Plot.LINE);
    plot.setColor(cfg.polynomS2FinalColor);
    plot.addPoints(xVals, sigma2ValsAll, Plot.LINE);

    //legend
    plot.setColor(cfg.polynomS1FinalColor);
    plot.addLabel(cfg.legend1X, cfg.legend1Y, cfg.legend1Label);
    plot.setColor(cfg.polynomS2FinalColor);
    plot.addLabel(cfg.legend2X, cfg.legend2Y, cfg.legend2Label);
}
 
Example #4
Source File: AbstractCalibrationProcess.java    From thunderstorm with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void drawSigmaPlots() {
    // config
    SigmaPlotConfig cfg = new SigmaPlotConfig();
    cfg.allFrames = allFrames;
    cfg.allSigma1s = allSigma1s;
    cfg.allSigma2s = allSigma2s;
    cfg.allPolynomsS1 = allPolynomsS1;
    cfg.allPolynomsS2 = allPolynomsS2;
    cfg.polynomS1Final = polynomS1Final;
    cfg.polynomS2Final = polynomS2Final;
    cfg.allSigma1sColor = new Color(255, 200, 200);
    cfg.allSigma2sColor = new Color(200, 200, 255);
    cfg.allPolynomsS1Color = new Color(255, 230, 230);
    cfg.allPolynomsS2Color = new Color(230, 230, 255);
    cfg.polynomS1FinalColor = new Color(255, 0, 0);
    cfg.polynomS2FinalColor = new Color(0, 0, 255);
    cfg.legend1X = 0.1;
    cfg.legend1Y = 0.8;
    cfg.legend1Label = "sigma1";
    cfg.legend2X = 0.1;
    cfg.legend2Y = 0.9;
    cfg.legend2Label = "sigma2";

    // create and setup plot
    Plot plot = new Plot("Sigma", "z [nm]", "sigma [px]", null, (float[]) null);
    plot.setSize(1024, 768);
    plot.setLimits(-2*zRange, +2*zRange, 0, stageStep);
    double[] xVals = new double[(int)(2*zRange/stageStep) * 2 + 1];
    for(int val = -2*(int)zRange, i = 0; val <= +2*(int)zRange; val += stageStep, i++) {
        xVals[i] = val;
    }
    plot.draw();

    // plot
    drawSigmaPlots(plot, xVals, cfg);

    // display
    plot.show();
}
 
Example #5
Source File: ResultsDriftCorrection.java    From thunderstorm with GNU General Public License v3.0 5 votes vote down vote up
public static void showDriftPlot(DriftResults driftCorrection) {
    int minFrame = driftCorrection.getMinFrame();
    int maxFrame = driftCorrection.getMaxFrame();
    int gridTicks = 200;
    double tickStep = (maxFrame - minFrame) / (double) gridTicks;
    double[] grid = new double[gridTicks];
    double[] driftX = new double[gridTicks];
    double[] driftY = new double[gridTicks];
    for(int i = 0; i < gridTicks; i++) {
        grid[i] = i * tickStep + minFrame;
        Point2D.Double offset = driftCorrection.getInterpolatedDrift(grid[i]);
        driftX[i] = offset.x;
        driftY[i] = offset.y;
    }
    Plot plot = new Plot("Drift", "frame", "drift [" + driftCorrection.getUnits() + "]", (float[]) null, null);
    if(driftCorrection.getDriftDataX().length > 50) {
        plot.setFrameSize(1280, 720);
    }
    plot.setLimits(minFrame, driftCorrection.getMaxFrame(),
            Math.min(VectorMath.min(driftCorrection.getDriftDataX()), VectorMath.min(driftCorrection.getDriftDataY())),
            Math.max(VectorMath.max(driftCorrection.getDriftDataX()), VectorMath.max(driftCorrection.getDriftDataY())));
    plot.setColor(new Color(255, 128, 128));
    plot.addPoints(driftCorrection.getDriftDataFrame(), driftCorrection.getDriftDataX(), Plot.CROSS);
    plot.draw();
    plot.setColor(new Color(128, 255, 128));
    plot.addPoints(driftCorrection.getDriftDataFrame(), driftCorrection.getDriftDataY(), Plot.CROSS);
    plot.setColor(Color.red);
    plot.addPoints(grid, driftX, Plot.LINE);
    plot.addLabel(0.05, 0.8, "x drift");
    plot.setColor(Color.green);
    plot.addPoints(grid, driftY, Plot.LINE);
    plot.addLabel(0.05, 0.9, "y drift");
    plot.show();
}
 
Example #6
Source File: AstigmaticBiplaneCalibrationProcess.java    From thunderstorm with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void drawSigmaPlots() {
    // config plane 1
    SigmaPlotConfig cfg1 = new SigmaPlotConfig();
    cfg1.allFrames = allFrames1;
    cfg1.allSigma1s = allSigma11s;
    cfg1.allSigma2s = allSigma12s;
    cfg1.allPolynomsS1 = allPolyS11;
    cfg1.allPolynomsS2 = allPolyS12;
    cfg1.polynomS1Final = polyS11;
    cfg1.polynomS2Final = polyS12;
    cfg1.allSigma1sColor = new Color(255, 200, 200);
    cfg1.allSigma2sColor = new Color(200, 200, 255);
    cfg1.allPolynomsS1Color = new Color(255, 230, 230);
    cfg1.allPolynomsS2Color = new Color(230, 230, 255);
    cfg1.polynomS1FinalColor = new Color(255, 0, 0);
    cfg1.polynomS2FinalColor = new Color(0, 0, 255);
    cfg1.legend1X = 0.1;
    cfg1.legend1Y = 0.8;
    cfg1.legend1Label = "sigma11";
    cfg1.legend2X = 0.1;
    cfg1.legend2Y = 0.9;
    cfg1.legend2Label = "sigma12";

    // config plane 2
    SigmaPlotConfig cfg2 = new SigmaPlotConfig();
    cfg2.allFrames = allFrames2;
    cfg2.allSigma1s = allSigma21s;
    cfg2.allSigma2s = allSigma22s;
    cfg2.allPolynomsS1 = allPolyS21;
    cfg2.allPolynomsS2 = allPolyS22;
    cfg2.polynomS1Final = polyS21;
    cfg2.polynomS2Final = polyS22;
    cfg2.allSigma1sColor = new Color(255, 200, 255);
    cfg2.allSigma2sColor = new Color(200, 255, 255);
    cfg2.allPolynomsS1Color = new Color(255, 230, 255);
    cfg2.allPolynomsS2Color = new Color(230, 255, 255);
    cfg2.polynomS1FinalColor = new Color(255, 0, 255);
    cfg2.polynomS2FinalColor = new Color(0, 255, 255);
    cfg2.legend1X = 0.2;
    cfg2.legend1Y = 0.8;
    cfg2.legend1Label = "sigma21";
    cfg2.legend2X = 0.2;
    cfg2.legend2Y = 0.9;
    cfg2.legend2Label = "sigma22";

    // create and setup plot
    Plot plot = new Plot("Sigma", "z [nm]", "sigma [px]", null, (float[]) null);
    plot.setSize(1024, 768);
    plot.setLimits(-2*zRange, +2*zRange, 0, stageStep);
    double[] xVals = new double[(int)(2*zRange/stageStep) * 2 + 1];
    for(int val = -2*(int)zRange, i = 0; val <= +2*(int)zRange; val += stageStep, i++) {
        xVals[i] = val;
    }
    plot.draw();

    // plot
    drawSigmaPlots(plot, xVals, cfg1);
    drawSigmaPlots(plot, xVals, cfg2);

    // display
    plot.show();
}
 
Example #7
Source File: InteractivePlotter.java    From Scripts with GNU General Public License v3.0 4 votes vote down vote up
private void setPlotFont() {

		if (plot == null)
			return;

		final String[] FONTS = new String[] { Font.SANS_SERIF, Font.MONOSPACED, Font.SERIF };
		final String[] STYLES = { "Plain", "Bold", "Italic", "Bold+Italic" };
		final String[] JUSTIFICATIONS = { "Left", "Center", "Right" };
		final String[] SCOPES = { "Plot", "Both Axes Titles", "X-axis Title", "Y-axis Title" };
		final String[] CHOICE_DEFAULTS = { FONTS[0], STYLES[0], JUSTIFICATIONS[0], SCOPES[0] };
		final int[] INT_STYLES = { Font.PLAIN, Font.BOLD, Font.ITALIC, Font.BOLD + Font.ITALIC };
		final int[] INT_JUSTIFICATIONS = { Plot.LEFT, Plot.CENTER, Plot.RIGHT };
		final int DEF_SIZE = 12;
		final boolean DEF_ANTIALISED = true;

		final GenericDialog fgd = new GenericDialog("Font Options");
		fgd.addChoice("Type:", FONTS, CHOICE_DEFAULTS[0]);
		fgd.addChoice("Style:", STYLES, CHOICE_DEFAULTS[1]);
		fgd.addChoice("Justification:", JUSTIFICATIONS, CHOICE_DEFAULTS[2]);
		fgd.addSlider("Size:", 9, 24, DEF_SIZE);
		fgd.setInsets(0, 20, 15);
		fgd.addCheckbox("Antialiased text", DEF_ANTIALISED);
		fgd.addChoice("Apply to:", SCOPES, CHOICE_DEFAULTS[3]);
		fgd.hideCancelButton();
		fgd.addHelp("");
		fgd.setHelpLabel("Apply Defaults");
		fgd.addDialogListener(new DialogListener() {
			@Override
			public boolean dialogItemChanged(final GenericDialog gd, final AWTEvent e) {
				if (e != null && e.toString().contains("Apply Defaults")) {
					@SuppressWarnings("unchecked")
					final Vector<Choice> nChoices = gd.getChoices();
					for (final Choice choice : nChoices)
						choice.select(CHOICE_DEFAULTS[nChoices.indexOf(choice)]);
					((TextField) gd.getNumericFields().get(0)).setText(Integer.toString(DEF_SIZE));
					((Checkbox) gd.getCheckboxes().get(0)).setState(DEF_ANTIALISED);
				}

				final String type = FONTS[fgd.getNextChoiceIndex()];
				final int style = INT_STYLES[fgd.getNextChoiceIndex()];
				final int justification = INT_JUSTIFICATIONS[fgd.getNextChoiceIndex()];
				final int size = (int) fgd.getNextNumber();
				final int scopeIdx = fgd.getNextChoiceIndex();

				plot.setJustification(justification);
				plot.setAntialiasedText(fgd.getNextBoolean());
				final Font font = new Font(type, style, size);
				switch (scopeIdx) {
				case 1: // SCOPES[1]
					plot.setXLabelFont(font);
					plot.setYLabelFont(font);
					break;
				case 2: // SCOPES[2]
					plot.setXLabelFont(font);
					break;
				case 3: // SCOPES[3]
					plot.setYLabelFont(font);
					break;
				default:
					plot.setFont(font);
					plot.setXLabelFont(font);
					plot.setYLabelFont(font);
					break;
				}

				plot.updateImage();
				return true;
			}
		});
		showAsSubDialog(fgd);
		if (!fgd.wasOKed())
			return;
	}