Scatter plot of data
Source code name: "xchart_scatter.java"
Programming language: Java
Topic: Plots/2D
DMelt Version 3. Last modified: 04/05/1977. License: Free
https://datamelt.org/code/cache/xchart_scatter_5484.java
To run this script using the DataMelt IDE,
copy the above URL link to the menu [File]→[Read script from URL] of the DMelt IDE.
import java.util.LinkedList;
import java.util.List;
import java.util.Random;
import org.knowm.xchart.SwingWrapper;
import org.knowm.xchart.XYChart;
import org.knowm.xchart.XYChartBuilder;
import org.knowm.xchart.XYSeries;
import org.knowm.xchart.XYSeries.XYSeriesRenderStyle;
import org.knowm.xchart.style.Styler;
import org.knowm.xchart.style.markers.SeriesMarkers;
/**
* Gaussian Blob
*
* Demonstrates the following:
*
*
* ChartType.Scatter
* Series data as a Set
* Setting marker size
* Formatting of negative numbers with large magnitude but small differences
* YAxis position on Right
*
Cross type series marker
*/
public class xchart_scatter {
public static void main(String[] args) {
XYChart chart = getChart();
new SwingWrapper<>(chart).displayChart();
}
static public XYChart getChart() {
XYChart chart = new XYChartBuilder().width(600).height(400).build();
chart.getStyler().setDefaultSeriesRenderStyle(XYSeriesRenderStyle.Scatter);
chart.getStyler().setChartTitleVisible(false);
chart.getStyler().setLegendVisible(false);
chart.getStyler().setMarkerSize(16);
chart.getStyler().setYAxisGroupPosition(0, Styler.YAxisPosition.Right);
List xData = new LinkedList();
List yData = new LinkedList();
Random random = new Random();
int size = 1000;
for (int i = 0; i < size; i++) {
xData.add(random.nextGaussian() / 1000);
yData.add(-1000000 + random.nextGaussian());
}
XYSeries series = chart.addSeries("Gaussian Blob", xData, yData);
series.setMarker(SeriesMarkers.CROSS);
return chart;
}
}