de.erichseifert.gral.plots.XYPlot Java Examples

The following examples show how to use de.erichseifert.gral.plots.XYPlot. 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: SineGraph.java    From Java-Data-Science-Cookbook with MIT License 6 votes vote down vote up
public SineGraph() throws FileNotFoundException, IOException {
	setDefaultCloseOperation(EXIT_ON_CLOSE);
	setSize(1600, 1400);

	DataTable data = new DataTable(Double.class, Double.class);
	for (double x = -5.0; x <= 5.0; x+=0.25) {
           double y = 5.0*Math.sin(x);
           data.add(x, y);
       }

	XYPlot plot = new XYPlot(data);
	getContentPane().add(new InteractivePanel(plot));
	LineRenderer lines = new DefaultLineRenderer2D();
	plot.setLineRenderer(data, lines);
	Color color = new Color(0.0f, 0.0f, 0.0f);
	plot.getPointRenderer(data).setColor(color);
	plot.getLineRenderer(data).setColor(color);
}
 
Example #2
Source File: ScatterPlot.java    From Java-Data-Science-Cookbook with MIT License 6 votes vote down vote up
@SuppressWarnings("unchecked")
public ScatterPlot() {
	// Generate 100,000 data points
	DataTable data = new DataTable(Double.class, Double.class);
	for (int i = 0; i <= SAMPLE_COUNT; i++) {
		data.add(random.nextGaussian()*2.0,  random.nextGaussian()*2.0);
	}

	// Create a new xy-plot
	XYPlot plot = new XYPlot(data);

	// Format plot
	plot.setInsets(new Insets2D.Double(20.0, 40.0, 40.0, 40.0));
	plot.getTitle().setText(getDescription());

	// Format points
	plot.getPointRenderer(data).setColor(COLOR1);

	// Add plot to Swing component
	add(new InteractivePanel(plot), BorderLayout.CENTER);
}
 
Example #3
Source File: AreaPlot.java    From Java-Data-Science-Cookbook with MIT License 5 votes vote down vote up
public AreaPlot() {
	// Generate data
	DataTable data = new DataTable(Double.class, Double.class, Double.class, Double.class);
	for (double x = 0.0; x < 50; x ++) {
		double y1 = Double.NaN, y2 = Double.NaN, y3 = Double.NaN;
		y1 = random.nextGaussian();
		y2 = random.nextGaussian();
		y3 = random.nextGaussian();
		data.add(x, y1, y2, y3);
	}

	// Create data series
	DataSeries data1 = new DataSeries("series 1", data, 0, 1);
	DataSeries data2 = new DataSeries("series 2", data, 0, 2);
	DataSeries data3 = new DataSeries("series 3", data, 0, 3);

	// Create new xy-plot
	XYPlot plot = new XYPlot(data1, data2, data3);
	plot.setLegendVisible(true);
	plot.setInsets(new Insets2D.Double(20.0, 40.0, 20.0, 20.0));

	// Format data series
	formatFilledArea(plot, data1, COLOR2);
	formatFilledArea(plot, data2, COLOR1);
	formatLineArea(plot, data3, GraphicsUtils.deriveDarker(COLOR1));

	// Add plot to Swing component
	add(new InteractivePanel(plot));
}
 
Example #4
Source File: AreaPlot.java    From Java-Data-Science-Cookbook with MIT License 5 votes vote down vote up
private static void formatFilledArea(XYPlot plot, DataSource data, Color color) {
	PointRenderer point = new DefaultPointRenderer2D();
	point.setColor(color);
	plot.setPointRenderer(data, point);
	LineRenderer line = new DefaultLineRenderer2D();
	line.setColor(color);
	line.setGap(3.0);
	line.setGapRounded(true);
	plot.setLineRenderer(data, line);
	AreaRenderer area = new DefaultAreaRenderer2D();
	area.setColor(GraphicsUtils.deriveWithAlpha(color, 64));
	plot.setAreaRenderer(data, area);
}
 
Example #5
Source File: AreaPlot.java    From Java-Data-Science-Cookbook with MIT License 5 votes vote down vote up
private static void formatLineArea(XYPlot plot, DataSource data, Color color) {
	PointRenderer point = new DefaultPointRenderer2D();
	point.setColor(color);
	plot.setPointRenderer(data, point);
	plot.setLineRenderer(data, null);
	AreaRenderer area = new LineAreaRenderer2D();
	area.setGap(3.0);
	area.setColor(color);
	plot.setAreaRenderer(data, area);
}
 
Example #6
Source File: ScatterPlot.java    From cf4j with Apache License 2.0 4 votes vote down vote up
@Override
protected AbstractPlot getGralPlot() {

  // Create XY plot with data
  DataTable data = new DataTable(Double.class, Double.class);
  for (Pair<Double, Double> point : this.points) {
    data.add(point.getFirst(), point.getSecond());
  }

  DataSeries series = new DataSeries("Series", data);

  XYPlot plot = new XYPlot(series);

  // Customize plot
  plot.setBackground(PlotSettings.getBackgroundColor());

  PointRenderer pr = new DefaultPointRenderer2D();
  pr.setShape(new Ellipse2D.Double(-3.0, -3.0, 6.0, 6.0));
  pr.setColor(GraphicsUtils.deriveWithAlpha(PlotSettings.getColor(0), 128));
  plot.setPointRenderers(series, pr);

  plot.setInsets(
      new Insets2D.Double(
          PlotSettings.getClearInset(),
          PlotSettings.getyAxisInset(),
          PlotSettings.getxAxisInset(),
          PlotSettings.getClearInset()));

  // Customize x axis
  AxisRenderer xAxisRenderer = plot.getAxisRenderer(XYPlot.AXIS_X);

  xAxisRenderer.setLabel(new Label(xLabel));
  xAxisRenderer.getLabel().setFont(PlotSettings.getPrimaryFont());
  xAxisRenderer.setLabelDistance(PlotSettings.getxAxisLabelDistance());

  xAxisRenderer.setTickFont(PlotSettings.getSecondaryFont());
  xAxisRenderer.setTickLabelFormat(NumberFormat.getInstance(Locale.US));
  xAxisRenderer.setTicksAutoSpaced(true);

  // Customize y axis
  AxisRenderer yAxisRenderer = plot.getAxisRenderer(XYPlot.AXIS_Y);

  yAxisRenderer.setLabel(new Label(yLabel));
  yAxisRenderer.getLabel().setFont(PlotSettings.getPrimaryFont());
  yAxisRenderer.getLabel().setRotation(90);
  yAxisRenderer.setLabelDistance(PlotSettings.getyAxisLabelDistance());

  yAxisRenderer.setTickFont(PlotSettings.getSecondaryFont());
  yAxisRenderer.setTickLabelFormat(NumberFormat.getInstance(Locale.US));
  yAxisRenderer.setTicksAutoSpaced(true);

  xAxisRenderer.setIntersection(-Double.MAX_VALUE);
  yAxisRenderer.setIntersection(-Double.MAX_VALUE);

  // Customize navigator settings
  plot.getNavigator().setZoom(0.9);
  plot.getNavigator().setZoomable(false);

  return plot;
}