Search in sources :

Example 41 with XYPlot

use of org.jfree.chart.plot.XYPlot in project cytoscape-impl by cytoscape.

the class HeatMapLayer method createChart.

@Override
protected JFreeChart createChart(final XYZDataset dataset) {
    final PlotOrientation plotOrientation = orientation == Orientation.HORIZONTAL ? PlotOrientation.HORIZONTAL : PlotOrientation.VERTICAL;
    final SymbolAxis xAxis = new SymbolAxis(null, xLabels);
    xAxis.setVisible(showDomainAxis);
    xAxis.setAxisLineVisible(false);
    xAxis.setTickMarksVisible(false);
    xAxis.setTickLabelFont(xAxis.getLabelFont().deriveFont(axisFontSize));
    xAxis.setTickLabelPaint(axisColor);
    xAxis.setVerticalTickLabels(domainLabelPosition != LabelPosition.STANDARD);
    xAxis.setLowerMargin(0.0);
    xAxis.setUpperMargin(0.0);
    final SymbolAxis yAxis = new SymbolAxis(null, yLabels);
    yAxis.setVisible(showRangeAxis);
    yAxis.setAxisLineVisible(false);
    yAxis.setTickMarksVisible(false);
    yAxis.setTickLabelFont(yAxis.getLabelFont().deriveFont(axisFontSize));
    yAxis.setTickLabelPaint(axisColor);
    yAxis.setLowerMargin(0.0);
    yAxis.setUpperMargin(0.0);
    yAxis.setInverted(true);
    final XYBlockRenderer renderer = new XYBlockRenderer();
    if (range != null && range.size() >= 2 && range.get(0) != null && range.get(1) != null) {
        final int colorsSize = colors != null ? colors.size() : 0;
        Color upperColor = colorsSize > 0 ? colors.get(0) : Color.BLUE;
        Color zeroColor = colorsSize > 1 ? colors.get(1) : Color.WHITE;
        Color lowerColor = colorsSize > 2 ? colors.get(2) : Color.RED;
        Color nanColor = colorsSize > 3 ? colors.get(3) : Color.GRAY;
        final ColorScale scale = new ColorScale(range.get(0), range.get(1), lowerColor, zeroColor, upperColor, nanColor);
        renderer.setPaintScale(scale);
    }
    final XYPlot plot = new XYPlot(dataset, xAxis, yAxis, renderer);
    plot.setDomainAxis(xAxis);
    plot.setDomainAxisLocation(AxisLocation.TOP_OR_LEFT);
    plot.setRangeAxisLocation(AxisLocation.TOP_OR_LEFT);
    plot.setOutlineVisible(false);
    plot.setDomainGridlinesVisible(false);
    plot.setRangeGridlinesVisible(false);
    plot.setBackgroundPaint(TRANSPARENT_COLOR);
    plot.setInsets(new RectangleInsets(1.0, 1.0, 1.0, 1.0));
    plot.setAxisOffset(new RectangleInsets(1.0, 1.0, 1.0, 1.0));
    plot.setOrientation(plotOrientation);
    final JFreeChart chart = new JFreeChart(null, plot);
    chart.removeLegend();
    chart.setBorderVisible(false);
    chart.setBackgroundPaint(TRANSPARENT_COLOR);
    chart.setPadding(new RectangleInsets(0.0, 0.0, 0.0, 0.0));
    return chart;
}
Also used : PlotOrientation(org.jfree.chart.plot.PlotOrientation) XYPlot(org.jfree.chart.plot.XYPlot) Color(java.awt.Color) XYBlockRenderer(org.jfree.chart.renderer.xy.XYBlockRenderer) ColorScale(org.cytoscape.ding.internal.charts.util.ColorScale) RectangleInsets(org.jfree.ui.RectangleInsets) JFreeChart(org.jfree.chart.JFreeChart) SymbolAxis(org.jfree.chart.axis.SymbolAxis)

Example 42 with XYPlot

use of org.jfree.chart.plot.XYPlot in project gephi by gephi.

the class ChartsUtils method setScatterPlotLinesEnabled.

/**
 * Modify a scatter plot to show lines instead or shapes or not.
 * @param scatterPlot Scatter plot to modify
 * @param enabled Indicates if lines have to be shown
 */
public static void setScatterPlotLinesEnabled(final JFreeChart scatterPlot, final boolean enabled) {
    XYPlot plot = (XYPlot) scatterPlot.getPlot();
    XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer();
    if (enabled) {
        renderer.setSeriesLinesVisible(0, true);
        renderer.setSeriesShapesVisible(0, false);
    } else {
        renderer.setSeriesLinesVisible(0, false);
        renderer.setSeriesShapesVisible(0, true);
        renderer.setSeriesShape(0, new java.awt.geom.Ellipse2D.Double(0, 0, 1, 1));
    }
    renderer.setSeriesPaint(0, Color.RED);
    plot.setRenderer(0, renderer);
}
Also used : XYPlot(org.jfree.chart.plot.XYPlot) XYLineAndShapeRenderer(org.jfree.chart.renderer.xy.XYLineAndShapeRenderer)

Example 43 with XYPlot

use of org.jfree.chart.plot.XYPlot in project gephi by gephi.

the class ChartsUtils method setScatterPlotLinearRegressionEnabled.

/**
 * Modify a scatter plot to show linear regression or not.
 * @param scatterPlot Scatter plot to modify
 * @param enabled Indicates if linear regression has to be shown
 */
public static void setScatterPlotLinearRegressionEnabled(final JFreeChart scatterPlot, final boolean enabled) {
    XYPlot plot = (XYPlot) scatterPlot.getPlot();
    if (enabled) {
        StandardXYItemRenderer regressionRenderer = new StandardXYItemRenderer();
        regressionRenderer.setBaseSeriesVisibleInLegend(false);
        plot.setDataset(1, regress((XYSeriesCollection) plot.getDataset(0)));
        plot.setRenderer(1, regressionRenderer);
    } else {
        // Remove linear regression
        plot.setDataset(1, null);
    }
}
Also used : XYPlot(org.jfree.chart.plot.XYPlot) StandardXYItemRenderer(org.jfree.chart.renderer.xy.StandardXYItemRenderer) XYSeriesCollection(org.jfree.data.xy.XYSeriesCollection)

Example 44 with XYPlot

use of org.jfree.chart.plot.XYPlot in project gephi by gephi.

the class ChartsUtils method buildScatterPlot.

/**
 * Build new Scatter plot. Appearance can be changed later with the other methods of ChartsUtils.
 * @param data Data for the plot
 * @param title Title for the chart
 * @param xLabel Text for x label
 * @param yLabel Text for y label
 * @param useLines Indicates if lines have to be drawn instead of shapes
 * @param useLinearRegression Indicates if the scatter plot has to have linear regreesion line drawn
 * @return Scatter plot for the data and appearance options
 */
public static JFreeChart buildScatterPlot(final XYSeriesCollection data, final String title, final String xLabel, final String yLabel, final boolean useLines, final boolean useLinearRegression) {
    JFreeChart scatterPlot = ChartFactory.createXYLineChart(title, xLabel, yLabel, data, PlotOrientation.VERTICAL, true, true, false);
    XYPlot plot = (XYPlot) scatterPlot.getPlot();
    plot.setBackgroundPaint(java.awt.Color.WHITE);
    plot.setDomainGridlinePaint(java.awt.Color.GRAY);
    plot.setRangeGridlinePaint(java.awt.Color.GRAY);
    setScatterPlotLinesEnabled(scatterPlot, useLines);
    setScatterPlotLinearRegressionEnabled(scatterPlot, useLinearRegression);
    return scatterPlot;
}
Also used : XYPlot(org.jfree.chart.plot.XYPlot) JFreeChart(org.jfree.chart.JFreeChart)

Example 45 with XYPlot

use of org.jfree.chart.plot.XYPlot in project j6dof-flight-sim by chris-ali.

the class SimulationPlot method createPlots.

/**
 * Populates the {@link plotLists} List with {@link XYPlot} objects created from the logsOut ArrayList
 * argument. It first creates {@link XYSeries} objects with data from logsOut, adds those to
 * {@link XYSeriesCollection}, adds those series collections to {@link XYPlot} objects, and finally
 * puts the XYPlot objects into {@link plotList}. The types of {@link XYPlot} objects generated
 * comes from settings in {@link SubPlotBundle}
 *
 * @param logsOut
 * @param bundle
 */
private void createPlots(List<Map<SimOuts, Double>> logsOut, SubPlotBundle bundle) {
    for (SubPlotOptions option : bundle.getSubPlots()) {
        XYSeriesCollection collection = new XYSeriesCollection();
        for (SimOuts simout : option.getyData()) {
            XYSeries series = new XYSeries(simout.toString());
            xySeriesData.put(simout, series);
            collection.addSeries(series);
        }
        domainAxis = new NumberAxis(option.getxAxisName());
        rangeAxes.put(option.getTitle(), new NumberAxis(option.getyAxisName()));
        xyCollections.put(option.getTitle(), collection);
    }
    combinedDomPlot = new CombinedDomainXYPlot(domainAxis);
    updateXYSeriesData(logsOut, bundle);
    for (Map.Entry<String, XYSeriesCollection> entry : xyCollections.entrySet()) {
        logger.debug("Creating a subplot called: " + entry.getKey() + "...");
        XYPlot subPlot = new XYPlot(entry.getValue(), domainAxis, rangeAxes.get(entry.getKey()), new StandardXYItemRenderer());
        plotList.add(subPlot);
    }
}
Also used : XYSeries(org.jfree.data.xy.XYSeries) NumberAxis(org.jfree.chart.axis.NumberAxis) XYPlot(org.jfree.chart.plot.XYPlot) CombinedDomainXYPlot(org.jfree.chart.plot.CombinedDomainXYPlot) StandardXYItemRenderer(org.jfree.chart.renderer.xy.StandardXYItemRenderer) SimOuts(com.chrisali.javaflightsim.simulation.integration.SimOuts) XYSeriesCollection(org.jfree.data.xy.XYSeriesCollection) CombinedDomainXYPlot(org.jfree.chart.plot.CombinedDomainXYPlot) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) SubPlotOptions(com.chrisali.javaflightsim.swing.plotting.PlotConfiguration.SubPlotOptions)

Aggregations

XYPlot (org.jfree.chart.plot.XYPlot)160 JFreeChart (org.jfree.chart.JFreeChart)98 NumberAxis (org.jfree.chart.axis.NumberAxis)49 Color (java.awt.Color)43 XYLineAndShapeRenderer (org.jfree.chart.renderer.xy.XYLineAndShapeRenderer)35 ValueAxis (org.jfree.chart.axis.ValueAxis)34 DateAxis (org.jfree.chart.axis.DateAxis)33 XYDataset (org.jfree.data.xy.XYDataset)30 SimpleDateFormat (java.text.SimpleDateFormat)22 XYSeries (org.jfree.data.xy.XYSeries)22 TimeSeriesCollection (org.jfree.data.time.TimeSeriesCollection)21 XYSeriesCollection (org.jfree.data.xy.XYSeriesCollection)21 XYItemRenderer (org.jfree.chart.renderer.xy.XYItemRenderer)18 BasicStroke (java.awt.BasicStroke)16 Font (java.awt.Font)16 ChartPanel (org.jfree.chart.ChartPanel)16 StandardXYToolTipGenerator (org.jfree.chart.labels.StandardXYToolTipGenerator)16 DecimalFormat (java.text.DecimalFormat)13 Map (java.util.Map)13 LegendTitle (org.jfree.chart.title.LegendTitle)13