Example usage for org.jfree.chart ChartFactory createScatterPlot

List of usage examples for org.jfree.chart ChartFactory createScatterPlot

Introduction

In this page you can find the example usage for org.jfree.chart ChartFactory createScatterPlot.

Prototype

public static JFreeChart createScatterPlot(String title, String xAxisLabel, String yAxisLabel,
        XYDataset dataset, PlotOrientation orientation, boolean legend, boolean tooltips, boolean urls) 

Source Link

Document

Creates a scatter plot with default settings.

Usage

From source file:info.financialecology.finance.utilities.datastruct.VersatileChart.java

public void drawScatterPlot(VersatileDataTable acds, String... xyPairs) {
    ArrayList<JFreeChart> charts = new ArrayList<JFreeChart>();

    XYSeriesCollection dataSet = new XYSeriesCollection();
    XYSeries xySeries = new XYSeries("no_name");
    dataSet.addSeries(xySeries);//from w  ww  .j  a  v a  2 s . co  m

    for (int i = 0; i < xyPairs.length; i += 2) {
        List<String> rowKeys = acds.getRowKeys();

        for (String rowKey : rowKeys) {
            if (!StringUtils.startsWith(rowKey, "#")) {
                double xValue = acds.getValue(rowKey, xyPairs[i]).doubleValue();
                double yValue = acds.getValue(rowKey, xyPairs[i + 1]).doubleValue();
                xySeries.add(xValue, yValue);
            }
        }

        JFreeChart chart = ChartFactory.createScatterPlot(params.title, params.xLabel, params.yLabel, dataSet,
                PlotOrientation.VERTICAL, params.legend, params.toolTips, false);

        charts.add(chart);
    }

    ChartFrame frame;

    for (JFreeChart chart : charts) {
        frame = new ChartFrame("UNKNOWN", chart);
        frame.pack();
        frame.setVisible(true);
    }
}

From source file:org.openscience.cdk.applications.taverna.basicutilities.ChartTool.java

/**
 * Creates a residue plot.//from w w w . ja va2s .com
 * 
 * @param yValues
 * @param header
 * @param xAxis
 * @param yAxis
 * @param seriesNames
 * @return
 */
public JFreeChart createResiduePlot(List<Double[]> yValues, String header, String xAxis, String yAxis,
        List<String> seriesNames) {
    LinkedList<XYLineAnnotation> lines = new LinkedList<XYLineAnnotation>();
    DefaultXYDataset xyDataSet = new DefaultXYDataset();
    for (int j = 0; j < yValues.size(); j++) {
        XYSeries series = new XYSeries(seriesNames.get(j));
        for (int i = 0; i < yValues.get(j).length; i++) {
            series.add(i + 1, yValues.get(j)[i]);
            float dash[] = { 10.0f };
            BasicStroke stroke = new BasicStroke(1.0f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER, 10.0f,
                    dash, 0.0f);
            XYLineAnnotation annotation = new XYLineAnnotation(i + 1, 0, i + 1, yValues.get(j)[i], stroke,
                    Color.BLUE);
            lines.add(annotation);
        }
        xyDataSet.addSeries(seriesNames.get(j), series.toArray());
    }
    JFreeChart chart = ChartFactory.createScatterPlot(header, xAxis, yAxis, xyDataSet, PlotOrientation.VERTICAL,
            true, false, false);
    XYPlot plot = (XYPlot) chart.getPlot();
    plot.setNoDataMessage("NO DATA");
    plot.setDomainZeroBaselineVisible(true);
    plot.setRangeZeroBaselineVisible(true);
    for (int i = 0; i < lines.size(); i++) {
        plot.addAnnotation(lines.get(i));
    }
    XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) plot.getRenderer();
    renderer.setSeriesOutlinePaint(0, Color.black);
    renderer.setUseOutlinePaint(true);
    NumberAxis domainAxis = (NumberAxis) plot.getDomainAxis();
    domainAxis.setAutoRangeIncludesZero(false);
    domainAxis.setTickMarkInsideLength(2.0f);
    domainAxis.setTickMarkOutsideLength(0.0f);

    NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setTickMarkInsideLength(2.0f);
    rangeAxis.setTickMarkOutsideLength(0.0f);

    return chart;
}

From source file:com.deafgoat.ml.prognosticator.Charter.java

/**
 * Charts data set containing numeric attributes against with prediction
 * confidence//from w  ww . ja  v  a 2  s  .com
 * 
 * @param files
 *            List of files containing predictions to chart
 * @throws IOException
 *             If the list of files can not be read
 * @return chart The chart to be drawn
 */
public JFreeChart getNumericChart(String[] files) throws IOException {
    XYSeriesCollection dataset = createNumericDataset(files);
    JFreeChart chart = ChartFactory.createScatterPlot(_chartName, // chart
            // title
            "Values", // domain axis label
            "Confidence", // range axis label
            dataset, // data
            PlotOrientation.VERTICAL, // orientation
            true, // include legend
            true, // tooltips?
            false // URLs?
    );
    return chart;
}

From source file:com.comcast.cmb.test.tools.QueueDepthSimulator.java

public static void scatterPlot(Map<String, List<Double>> datasets, String filename, String title, String labelX,
        String labelY) throws IOException {
    XYSeriesCollection dataset = new XYSeriesCollection();
    for (String label : datasets.keySet()) {
        XYSeries data = new XYSeries(label);
        int cnt = 0;
        for (Double d : datasets.get(label)) {
            data.add(cnt, d);//from   w  w  w  .java  2 s  .  co  m
            cnt++;
        }
        dataset.addSeries(data);
    }
    JFreeChart chart = ChartFactory.createScatterPlot(title, labelX, labelY, dataset, PlotOrientation.VERTICAL,
            true, true, false);
    ChartUtilities.saveChartAsPNG(new File(filename), chart, 1024, 768);
}

From source file:org.squale.squaleweb.util.graph.ScatterMaker.java

/**
 * Construit (ou reconstruit) le diagramme puis le retourne
 * /*from   w w  w  . j a v a  2 s .co  m*/
 * @return le diagramme JFreeChart.
 */
protected JFreeChart getChart() {
    LOG.debug(WebMessages.getString("method.entry"));
    JFreeChart retChart = super.getChart();
    if (null == retChart) {
        // Gnration du Scatterplot
        retChart = ChartFactory.createScatterPlot(mTitle, mXLabel, mYLabel, mDataSet, PlotOrientation.VERTICAL,
                mShowLegend, false, false);
        ValueAxis domainAxis = retChart.getXYPlot().getDomainAxis();
        ValueAxis rangeAxis = retChart.getXYPlot().getRangeAxis();

        // Dtermination des bornes en abscisse et en ordonne
        double maxDomain = Math.max(domainAxis.getUpperBound(),
                DEFAULT_VERTICAL_AXIS_POS + DEFAULT_AXIS_MARGIN);
        double minDomain = Math.min(domainAxis.getLowerBound(),
                DEFAULT_VERTICAL_AXIS_POS - DEFAULT_AXIS_MARGIN);
        double maxRange = Math.max(rangeAxis.getUpperBound(),
                DEFAULT_HORIZONTAL_AXIS_POS + DEFAULT_AXIS_MARGIN);
        double minRange = Math.min(rangeAxis.getLowerBound(),
                DEFAULT_HORIZONTAL_AXIS_POS - DEFAULT_AXIS_MARGIN);

        // Mise  l'chelle logarithmique des axes
        LogarithmicAxis newDomainAxis = new LogarithmicAxis(domainAxis.getLabel());
        LogarithmicAxis newRangeAxis = new LogarithmicAxis(rangeAxis.getLabel());

        // Affectation des bornes en abscisse et en ordonne
        newDomainAxis.setLowerBound(minDomain);
        newDomainAxis.setUpperBound(maxDomain);
        newRangeAxis.setLowerBound(minRange);
        newRangeAxis.setUpperBound(maxRange);
        retChart.getXYPlot().setDomainAxis(newDomainAxis);
        retChart.getXYPlot().setRangeAxis(newRangeAxis);

        // Le point a une taille fixe
        Shape shape = new Rectangle(DEFAULT_POINT_SIZE, DEFAULT_POINT_SIZE);
        retChart.getXYPlot().getRenderer().setShape(shape);

        // Annotations
        XYLineAnnotation horizontalAxis = new XYLineAnnotation(minDomain, DEFAULT_HORIZONTAL_AXIS_POS,
                maxDomain, DEFAULT_HORIZONTAL_AXIS_POS);
        XYLineAnnotation verticalAxis = new XYLineAnnotation(DEFAULT_VERTICAL_AXIS_POS, minRange,
                DEFAULT_VERTICAL_AXIS_POS, maxRange);
        retChart.getXYPlot().addAnnotation(horizontalAxis);
        retChart.getXYPlot().addAnnotation(verticalAxis);

        super.setChart(retChart);
    }
    LOG.debug(WebMessages.getString("method.exit"));
    return retChart;
}

From source file:stratego.neural.net.SimulatedAnnealing.java

private static void plotDataSet(List<NamedDataSet> ArraySetList, String name, String xAxis, String yAxis,
        boolean legend) throws IOException {

    String plot_title = name;/*from   w  w  w  .ja  va 2  s . c  om*/
    XYSeriesCollection plotData = new XYSeriesCollection();

    for (NamedDataSet ns : ArraySetList) {
        XYSeries series = new XYSeries(ns.getName());
        double[] data = ns.getArray();
        for (int i = 0; i < data.length; i++) {
            series.add((double) i, data[i]);
        }

        plotData.addSeries(series);
    }

    String title = plot_title;
    String xAxisLabel = xAxis;
    String yAxisLabel = yAxis;
    PlotOrientation orientation = PlotOrientation.VERTICAL;
    //boolean legend = true; // might wanna set this to true at some point, but research the library
    boolean tooltips = false;
    boolean urls = false;
    JFreeChart chart = ChartFactory.createScatterPlot(title, xAxisLabel, yAxisLabel, plotData, orientation,
            legend, tooltips, urls);

    JPanel panel = new ChartPanel(chart);

    JFrame f = new JFrame();
    f.add(panel);
    f.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
    f.pack();
    f.setTitle(plot_title);

    f.setVisible(true);

    // ChartUtilities.saveChartAsJPEG(new File("src/Graphs/test_graph_1.JPEG"),chart,1280,1024);

}

From source file:org.simbrain.plot.projection.ProjectionGui.java

/**
 * Construct the Projection GUI./*from   w ww.  java 2  s  .c  o m*/
 */
public ProjectionGui(final GenericFrame frame, final ProjectionComponent component) {
    super(frame, component);
    setPreferredSize(new Dimension(500, 400));
    actionManager = new PlotActionManager(this);
    setLayout(new BorderLayout());

    // Generate the graph
    chart = ChartFactory.createScatterPlot("High Dimensional Projection", "Projection X", "Projection Y",
            getWorkspaceComponent().getProjectionModel().getDataset(), PlotOrientation.VERTICAL, false, true,
            false);
    // chart.getXYPlot().getDomainAxis().setRange(-100, 100);
    // chart.getXYPlot().getRangeAxis().setRange(-100, 100);
    chart.getXYPlot().setBackgroundPaint(Color.white);
    chart.getXYPlot().setDomainGridlinePaint(Color.gray);
    chart.getXYPlot().setRangeGridlinePaint(Color.gray);
    chart.getXYPlot().getDomainAxis().setAutoRange(true);
    chart.getXYPlot().getRangeAxis().setAutoRange(true);
    panel = new ChartPanel(chart);

    // Custom render points as dots (not squares) and use custom tooltips
    // that show high-d point
    CustomRenderer renderer = new CustomRenderer();
    chart.getXYPlot().setRenderer(renderer);
    renderer.setSeriesLinesVisible(0, false);
    renderer.setSeriesShape(0, new Ellipse2D.Double(-5, -5, 5, 5));
    CustomToolTipGenerator generator = new CustomToolTipGenerator();
    renderer.setSeriesToolTipGenerator(0, generator);

    // Toolbar
    openBtn.setToolTipText("Open high-dimensional data");
    saveBtn.setToolTipText("Save data");
    projectionList.setMaximumSize(new java.awt.Dimension(200, 100));
    iterateBtn.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            getWorkspaceComponent().getProjector().iterate();
            update();
        }
    });
    clearBtn.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            getWorkspaceComponent().getWorkspace().stop();
            Executors.newSingleThreadExecutor().execute(new Runnable() {
                @Override
                public void run() {
                    getWorkspaceComponent().clearData();
                }
            });
        }
    });
    playBtn.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            if (getWorkspaceComponent().getProjectionModel().isRunning()) {
                playBtn.setIcon(ResourceManager.getImageIcon("Stop.png"));
                playBtn.setToolTipText("Stop iterating projection algorithm");
                getWorkspaceComponent().getProjectionModel().setRunning(false);
                Executors.newSingleThreadExecutor().execute(new ProjectionUpdater(getWorkspaceComponent()));
            } else {
                playBtn.setIcon(ResourceManager.getImageIcon("Play.png"));
                playBtn.setToolTipText("Start iterating projection algorithm");
                getWorkspaceComponent().getProjectionModel().setRunning(true);
            }
        }
    });
    prefsBtn.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            // TODO (Still working out overall dialog structure).
        }
    });
    randomBtn.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            getWorkspaceComponent().getProjector().randomize(100);
        }
    });
    theToolBar.add(projectionList);
    playBtn.setToolTipText("Iterate projection algorithm");
    theToolBar.add(playBtn);
    iterateBtn.setToolTipText("Step projection algorithm");
    theToolBar.add(iterateBtn);
    clearBtn.setToolTipText("Clear current data");
    theToolBar.add(clearBtn);
    randomBtn.setToolTipText("Randomize datapoints");
    theToolBar.add(randomBtn);
    theToolBar.addSeparator();
    warningLabel.setPreferredSize(new Dimension(16, 16));
    warningLabel.setToolTipText("This method works best with more " + "datapoints already added");
    theToolBar.add(warningLabel);
    String stepSizeToolTip = "Scales the amount points are moved on each iteration";
    JLabel stepSizeLabel = new JLabel("Step Size");
    stepSizeLabel.setToolTipText(stepSizeToolTip);
    sammonStepSizePanel.add(stepSizeLabel);
    try {
        sammonStepSize = new JTextField("" + SimbrainPreferences.getDouble("projectorSammonEpsilon"));
    } catch (PropertyNotFoundException e1) {
        e1.printStackTrace();
    }
    sammonStepSize.setColumns(3);
    sammonStepSize.setToolTipText(stepSizeToolTip);
    sammonStepSizePanel.add(sammonStepSize);
    theToolBar.add(sammonStepSizePanel);
    adjustDimension1.setToolTipText("Dimension 1");
    adjustDimension2.setToolTipText("Dimension 2");
    theToolBar.add(adjustDimension1);
    theToolBar.add(adjustDimension2);

    // Help button
    JButton helpButton = new JButton();
    helpButton.setAction(helpAction);

    // Add/Remove dimension buttons
    JButton addButton = new JButton("Add Dimension");
    addButton.setActionCommand("Add");
    addButton.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            getWorkspaceComponent().getProjectionModel().addSource();
        }
    });
    JButton deleteButton = new JButton("Remove Dimension");
    deleteButton.setActionCommand("Delete");
    deleteButton.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            getWorkspaceComponent().getProjectionModel().removeSource();
        }
    });

    // Button Panel
    JPanel buttonPanel = new JPanel();
    buttonPanel.add(helpButton);
    buttonPanel.add(addButton);
    buttonPanel.add(deleteButton);

    // Setup Menu Bar
    createAttachMenuBar();

    // Status Bar
    statusBar.add(pointsLabel);
    statusBar.add(dimsLabel);
    errorBar.add(errorLabel);

    // Bottom panel
    bottomPanel.add("North", buttonPanel);
    JPanel southPanel = new JPanel();
    southPanel.add(errorBar);
    southPanel.add(statusBar);
    bottomPanel.add("South", southPanel);

    // Put all panels together
    add("North", theToolBar);
    add("Center", panel);
    add("South", bottomPanel);

    // Other initialization
    initializeComboBoxes();
    addListeners();
    updateToolBar();
    update();

}

From source file:org.gephi.statistics.plugin.EigenvectorCentrality.java

/**
 * //from  ww w  . j ava 2s.  co  m
 * @return
 */
public String getReport() {
    //distribution of values
    Map<Double, Integer> dist = new HashMap<Double, Integer>();
    for (int i = 0; i < centralities.length; i++) {
        Double d = centralities[i];
        if (dist.containsKey(d)) {
            Integer v = dist.get(d);
            dist.put(d, v + 1);
        } else {
            dist.put(d, 1);
        }
    }

    //Distribution series
    XYSeries dSeries = ChartUtils.createXYSeries(dist, "Eigenvector Centralities");

    XYSeriesCollection dataset = new XYSeriesCollection();
    dataset.addSeries(dSeries);

    JFreeChart chart = ChartFactory.createScatterPlot("Eigenvector Centrality Distribution", "Score", "Count",
            dataset, PlotOrientation.VERTICAL, true, false, false);
    chart.removeLegend();
    ChartUtils.decorateChart(chart);
    ChartUtils.scaleChart(chart, dSeries, true);
    String imageFile = ChartUtils.renderChart(chart, "eigenvector-centralities.png");

    String report = "<HTML> <BODY> <h1>Eigenvector Centrality Report</h1> " + "<hr>" + "<h2> Parameters: </h2>"
            + "Network Interpretation:  " + (isDirected ? "directed" : "undirected") + "<br>"
            + "Number of iterations: " + numRuns + "<br>" + "Sum change: " + sumChange
            + "<br> <h2> Results: </h2>" + imageFile + "</BODY></HTML>";

    return report;

}

From source file:ch.zhaw.ias.dito.ui.AnalysisPanel.java

private JPanel createDecompositionPanel(String title, double[][] mdsValues) {
    JFreeChart chart = ChartFactory.createScatterPlot(title, null, null, new MdsXYDataset(mdsValues),
            PlotOrientation.VERTICAL, false, true, false);
    XYPlot plot = (XYPlot) chart.getPlot();
    plot.getRenderer().setBaseToolTipGenerator(new XYToolTipGenerator() {
        @Override//  w  w  w  .  jav a  2s  .  c o  m
        public String generateToolTip(XYDataset dataset, int series, int item) {
            return "item #" + (item + 1);
        }
    });

    JPanel mdsPanel = new JPanel(new BorderLayout(0, 10));
    mdsPanel.add(new ChartPanel(chart), BorderLayout.CENTER);
    dimensionsCombo = new JComboBox(new Integer[] { 2, 3 });
    JButton exportButton = new JButton(Translation.INSTANCE.get("s4.bu.exportDecomposition"));
    exportButton.addActionListener(this);
    JPanel mdsInputPanel = new JPanel();
    mdsInputPanel.setLayout(new BoxLayout(mdsInputPanel, BoxLayout.LINE_AXIS));
    mdsInputPanel.add(Box.createHorizontalGlue());
    mdsInputPanel.add(Box.createHorizontalGlue());
    mdsInputPanel.add(new JLabel(Translation.INSTANCE.get("s4.lb.dimension")));
    mdsInputPanel.add(Box.createHorizontalStrut(10));
    mdsInputPanel.add(dimensionsCombo);
    mdsInputPanel.add(Box.createHorizontalStrut(10));
    mdsInputPanel.add(exportButton);
    mdsPanel.add(mdsInputPanel, BorderLayout.SOUTH);

    return mdsPanel;
}

From source file:org.esa.beam.pixex.output.ScatterPlotDecoratingStrategy.java

private JFreeChart createScatterPlot(PixExOp.VariableCombination variableCombination, XYSeries dataset,
        long productId) {
    final XYSeriesCollection data = new XYSeriesCollection();
    data.addSeries(dataset);//  ww  w. j  a v a 2 s.c  o m
    String scatterPlotName = String.format("Scatter plot of '%s' and '%s' for product '%s'",
            variableCombination.originalVariableName, variableCombination.productVariableName,
            productNames.get(productId));
    return ChartFactory.createScatterPlot(scatterPlotName, variableCombination.originalVariableName,
            variableCombination.productVariableName, data, PlotOrientation.VERTICAL, false, false, false);
}