本文整理汇总了Java中de.erichseifert.gral.data.DataSeries类的典型用法代码示例。如果您正苦于以下问题:Java DataSeries类的具体用法?Java DataSeries怎么用?Java DataSeries使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
DataSeries类属于de.erichseifert.gral.data包,在下文中一共展示了DataSeries类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: setUpBeforeClass
import de.erichseifert.gral.data.DataSeries; //导入依赖的package包/类
@BeforeClass
@SuppressWarnings("unchecked")
public static void setUpBeforeClass() {
table = new DataTable(Integer.class, Integer.class, Integer.class);
table.add(1, 3, 5); // 0
table.add(2, 8, 2); // 1
table.add(3, 5, 6); // 2
table.add(4, 6, 2); // 3
table.add(5, 4, 1); // 4
table.add(6, 9, 5); // 5
table.add(7, 8, 7); // 6
table.add(8, 1, 9); // 7
series1 = new DataSeries("series1", table, 0, 1);
series2 = new DataSeries("series2", table, 1, 2);
}
示例2: testDataAdd
import de.erichseifert.gral.data.DataSeries; //导入依赖的package包/类
@Test
public void testDataAdd() {
int sizeBefore, size;
// Append
DataSeries series3 = new DataSeries("series3", table, 0, 2);
sizeBefore = plot.getData().size();
plot.add(series3);
size = plot.getData().size();
assertEquals(sizeBefore + 1, size);
assertEquals(series3, plot.get(size - 1));
// Insert
DataSeries series4 = new DataSeries("series4", table, 0);
sizeBefore = plot.getData().size();
plot.add(0, series4, false);
size = plot.getData().size();
assertEquals(sizeBefore + 1, size);
assertEquals(series4, plot.get(0));
assertFalse(plot.isVisible(series4));
}
示例3: AreaPlot
import de.erichseifert.gral.data.DataSeries; //导入依赖的package包/类
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));
}
示例4: render
import de.erichseifert.gral.data.DataSeries; //导入依赖的package包/类
@Override
public void render(Canvas componentCanvas, PLLineChartBlock component) {
PLLinePlotData data = component.getData();
if(data != null){
int linesCount = data.getY().size();
Class[] classes = Arrays.stream((new Class[linesCount + 1])).map(v -> Double.class).toArray(Class[]::new);
DataTable dataTable = new DataTable(classes);
for(int i = 0;i < linesCount;i++){
final int index = i;
Double[] points = Stream.concat(Stream.of(data.getX().get(index)),
data.getY().stream().map(lineData -> lineData.getY().get(index))).toArray(Double[]::new);
dataTable.add(points);
}
DataSeries[] dataSeries = IntStream.range(0, linesCount).mapToObj(index -> new DataSeries(data.getY().get(index).getName(), dataTable, 0, index + 1)).toArray(DataSeries[]::new);
XYPlot plot = new XYPlot(dataSeries);
super.preparePlot(plot, component);
plot.getAxisRenderer(XYPlot.AXIS_X).setIntersection(-Double.MAX_VALUE);
plot.getAxisRenderer(XYPlot.AXIS_Y).setIntersection(-Double.MAX_VALUE);
Color[] seriesColor = (component.getData().getY() == null)?null:component.getData().getY().stream().map(point -> PLColor.create(point.getColor(), Color.class)).toArray(Color[]::new);
if(seriesColor != null){
for(int i = 0;i < seriesColor.length;i++){
try{
PointRenderer ptRenderer = new DefaultPointRenderer2D();
LineRenderer lineRenderer = new DefaultLineRenderer2D();
Color lineColor = seriesColor[i];
ptRenderer.setColor(lineColor);
lineRenderer.setColor(lineColor);
plot.setPointRenderers(dataSeries[i], ptRenderer);
plot.setLineRenderers(dataSeries[i], lineRenderer);
}catch(Exception e){
logger.error("Error caused when trying to set color for a series", e);
}
}
}
super.drawPlot(plot, component, componentCanvas);
}else{
logger.warn("data not set, not rendering " + component);
}
}
示例5: AreaPlot
import de.erichseifert.gral.data.DataSeries; //导入依赖的package包/类
@SuppressWarnings("unchecked")
public AreaPlot() {
// Generate data
DataTable data = new DataTable(Double.class, Double.class, Double.class, Double.class);
for (double x=0.0; x<2.5*Math.PI; x+=Math.PI/15.0) {
double y1 = Double.NaN, y2 = Double.NaN, y3 = Double.NaN;
if (x>=0.00*Math.PI && x<2.25*Math.PI) {
y1 = 4.0*Math.sin(x + 0.5*Math.PI) + 0.1*random.nextGaussian();
}
if (x>=0.25*Math.PI && x<2.50*Math.PI) {
y2 = 4.0*Math.cos(x + 0.5*Math.PI) + 0.1*random.nextGaussian();
}
if (x>=0.00*Math.PI && x<2.50*Math.PI) {
y3 = 2.0*Math.sin(2.0*x/2.5) + 0.1*random.nextGaussian();
}
data.add(x, y1, y2, y3);
}
// Create data series
DataSeries data1 = new DataSeries("red", data, 0, 1);
DataSeries data2 = new DataSeries("blue 1", data, 0, 2);
DataSeries data3 = new DataSeries("blue 2", 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));
}
示例6: DrawableWriterTest
import de.erichseifert.gral.data.DataSeries; //导入依赖的package包/类
@SuppressWarnings("unchecked")
public DrawableWriterTest() {
DataTable data = new DataTable(Double.class, Double.class, Double.class, Double.class);
data.add(1.0, 4.5, 4.3, 4.0);
data.add(1.5, 5.5, 5.3, 5.0);
data.add(3.0, 3.5, 3.7, 4.0);
data.add(4.0, 4.7, 4.5, 4.3);
DataSeries s1 = new DataSeries(data, 0, 1);
DataSeries s2 = new DataSeries(data, 0, 2);
DataSeries s3 = new DataSeries(data, 0, 3);
plot = new XYPlot(s1, s2, s3);
plot.setInsets(new Insets2D.Double(20, 50, 50, 20));
LineRenderer lr1 = new DefaultLineRenderer2D();
lr1.setColor(Color.RED);
plot.setLineRenderers(s1, lr1);
LineRenderer lr2 = new DefaultLineRenderer2D();
lr2.setColor(Color.GREEN);
plot.setLineRenderers(s2, lr2);
LineRenderer lr3 = new DefaultLineRenderer2D();
lr3.setColor(Color.BLUE);
plot.setLineRenderers(s3, lr3);
}
示例7: DrawableWriterTest
import de.erichseifert.gral.data.DataSeries; //导入依赖的package包/类
@SuppressWarnings("unchecked")
public DrawableWriterTest() {
data = new DataTable(Double.class, Double.class, Double.class, Double.class);
data.add(1.0, 4.5, 4.3, 4.0);
data.add(1.5, 5.5, 5.3, 5.0);
data.add(3.0, 3.5, 3.7, 4.0);
data.add(4.0, 4.7, 4.5, 4.3);
DataSeries s1 = new DataSeries(data, 0, 1);
DataSeries s2 = new DataSeries(data, 0, 2);
DataSeries s3 = new DataSeries(data, 0, 3);
plot = new XYPlot(s1, s2, s3);
plot.setInsets(new Insets2D.Double(20, 50, 50, 20));
LineRenderer lr1 = new DefaultLineRenderer2D();
lr1.setColor(Color.RED);
plot.setLineRenderer(s1, lr1);
LineRenderer lr2 = new DefaultLineRenderer2D();
lr2.setColor(Color.GREEN);
plot.setLineRenderer(s2, lr2);
LineRenderer lr3 = new DefaultLineRenderer2D();
lr3.setColor(Color.BLUE);
plot.setLineRenderer(s3, lr3);
}
示例8: createXYPlot
import de.erichseifert.gral.data.DataSeries; //导入依赖的package包/类
/**
* creates a Plot for ctor()
* @param title
* @param list
* @param color
* @param clazz
* @return
*/
private XYPlot createXYPlot(String title, ArrayList<?> list, Color color, Class clazz)
{
// Create example data
DataSource histogram2d = null;
if(clazz == Long.class)
{
histogram2d = getLongHistogramDataSource((ArrayList<Long>)list);
}
else if(clazz == Double.class)
{
histogram2d = getDoubleHistogramDataSource((ArrayList<Double>)list);
}
DataSeries ds = new DataSeries("Data", histogram2d, 0, 1);
// Create new bar plot
XYPlot plot = new XYPlot(ds);
plot.getAxis(plot.AXIS_X).setAutoscaled(false);
plot.getAxis(plot.AXIS_Y).setAutoscaled(false);
// Format plot
plot.setInsets(new Insets2D.Double(20.0, 65.0, 50.0, 40.0));
plot.getTitle().setText(
String.format("%s (%d) pixels", title, list.size()));
final double KERNEL_VARIANCE = 3.0;
// Create a smoothed data series from a binomial (near-gaussian) convolution filter
Kernel kernelLowpass = KernelUtils.getBinomial(KERNEL_VARIANCE).normalize();
Filter dataLowpass = new Convolution(histogram2d, kernelLowpass, Filter.Mode.REPEAT, 1);
DataSeries dsLowpass = new DataSeries("Lowpass", dataLowpass, 0, 1);
plot.add(dsLowpass);
formatLineArea(plot, ds, color);
formatFilledArea(plot, dsLowpass, GraphicsUtils.deriveDarker(color));
return plot;
}
示例9: createSpecificPlot
import de.erichseifert.gral.data.DataSeries; //导入依赖的package包/类
private JPanel createSpecificPlot() {
GridResult grid = results.get(selectedIndex);
for (int i = 0; i < grid.test.size(); i++) {
dataSpecific.add((double)i, grid.test.get(i), grid.train.get(i) );
}
DataSeries seriesTest = new DataSeries("Test",dataSpecific, 0, 1);
DataSeries seriesTrain = new DataSeries("Training",dataSpecific, 0, 2);
// Create a new xy-plot
final XYPlot plot = new XYPlot(seriesTest,seriesTrain);
// Format plot
plot.setInsets(new Insets2D.Double(60, 60, 60, 20));
plot.getTitle().setText(grid.name);
plot.setLegendVisible(true);
plot.setLegendLocation(Location.NORTH);
specificPlot = plot;
SmoothLineRenderer2D renderTest = new SmoothLineRenderer2D();
renderTest.setColor(deriveDarker(Color.RED));
PointRenderer renderTestPoint = new DefaultPointRenderer2D();
renderTestPoint.setColor(renderTest.getColor());
plot.setLineRenderers(seriesTest, renderTest);
plot.setPointRenderers(seriesTest, renderTestPoint);
SmoothLineRenderer2D renderTrain = new SmoothLineRenderer2D();
renderTrain.setColor(deriveDarker(Color.BLUE));
PointRenderer renderTrainPoint = new DefaultPointRenderer2D();
renderTrainPoint.setColor(renderTrain.getColor());
plot.setLineRenderers(seriesTrain, renderTrain);
plot.setPointRenderers(seriesTrain, renderTrainPoint);
plot.getAxisRenderer(XYPlot.AXIS_X).getLabel().setText("Epoc");
plot.getAxisRenderer(XYPlot.AXIS_Y).getLabel().setText("Score");
plot.getAxis(XYPlot.AXIS_Y).setAutoscaled(false);
plot.getAxis(XYPlot.AXIS_Y).setRange(0,101);
specificPlotPanel = new InteractivePanel(plot);
JPanel wrapper = new JPanel();
wrapper.setLayout(new BorderLayout());
wrapper.add(specificPlotPanel,BorderLayout.CENTER);
wrapper.setBackground(Color.WHITE);
return wrapper;
}
示例10: createOverviewPlot
import de.erichseifert.gral.data.DataSeries; //导入依赖的package包/类
private InteractivePanel createOverviewPlot() {
double scale = percent ? 0.2 : 20.0;
// Create a new xy-plot
DataSeries series = new DataSeries(dataOverview);
updateOverviewData();
final XYPlot plot = new XYPlot(series);
// Format plot
plot.setInsets(new Insets2D.Double(20, 80, 60, 20));
plot.getTitle().setText(param0+" Vs "+param1);
overviewPlot = plot;
CustomInteractivePanel panel = new CustomInteractivePanel(plot,this);
overviewPlotPanel = panel;
// Format points
Color color = GraphicsUtils.deriveWithAlpha(Color.RED, 96);
SizeablePointRenderer pointRenderer = new SizeablePointRenderer();
pointRenderer.setShape(new Ellipse2D.Double(-0.5*scale, -0.5*scale, scale, scale)); // shape of data points
pointRenderer.setColor(color); // color of data points
pointRenderer.setColumn(2); // data column which determines the scaling of data point shapes
plot.setPointRenderers(series, pointRenderer); // Assign the point renderer to the data series
configureScatterAxis(control.scatterLog);
panel.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
Axis axisX = plot.getAxis(XYPlot.AXIS_X);
Axis axisY = plot.getAxis(XYPlot.AXIS_Y);
double bestDistance = Double.MAX_VALUE;
int bestIndex = -1;
double offX = plot.getPlotArea().getX();
double offY = plot.getPlotArea().getY();
double height = plot.getPlotArea().getHeight();
for (int i = 0; i < results.size(); i++) {
GridResult r = results.get(i);
double v0 = Double.parseDouble(r.parameters.get(param0));
double v1 = Double.parseDouble(r.parameters.get(param1));
double pixelX = plot.getAxisRenderer(XYPlot.AXIS_X).worldToView(axisX,v0,true);
double pixelY = plot.getAxisRenderer(XYPlot.AXIS_Y).worldToView(axisY,v1,true);
pixelX = offX + pixelX;
pixelY = offY + height - pixelY;
double dx = pixelX-e.getX();
double dy = pixelY-e.getY();
double d = dx*dx + dy*dy;
if( d < bestDistance ) {
bestDistance = d;
bestIndex = i;
}
}
if( bestDistance < maxClickDistance*maxClickDistance && bestIndex != -1 ) {
focusOnResult(bestIndex);
}
}
});
return panel;
}
示例11: SimpleXYPlot
import de.erichseifert.gral.data.DataSeries; //导入依赖的package包/类
@SuppressWarnings("unchecked")
public SimpleXYPlot() {
// Generate data
DataTable data = new DataTable(Double.class, Double.class, Double.class,
Double.class, Double.class, Double.class);
for (double x = 1.0; x <= 400.0; x *= 1.5) {
double x2 = x/5.0;
data.add(x2, -Math.sqrt(x2) + 5.0, 5.0*Math.log10(x2),
random.nextDouble() + 1.0, random.nextDouble() + 0.5, 1.0 + 2.0*random.nextDouble());
}
// Create data series
DataSeries seriesLog = new DataSeries(data, 0, 2, 3, 4);
DataSeries seriesLin = new DataSeries(data, 0, 1, 5);
// Create new xy-plot
XYPlot plot = new XYPlot(seriesLog, seriesLin);
// Format plot
plot.setInsets(new Insets2D.Double(20.0, 40.0, 40.0, 40.0));
plot.setBackground(Color.WHITE);
plot.getTitle().setText(getDescription());
// Format plot area
plot.getPlotArea().setBackground(new RadialGradientPaint(
new Point2D.Double(0.5, 0.5),
0.75f,
new float[] { 0.6f, 0.8f, 1.0f },
new Color[] { new Color(0, 0, 0, 0), new Color(0, 0, 0, 32), new Color(0, 0, 0, 128) }
));
plot.getPlotArea().setBorderStroke(null);
// Format axes
AxisRenderer axisRendererX = new LogarithmicRenderer2D();
AxisRenderer axisRendererY = plot.getAxisRenderer(XYPlot.AXIS_Y);
axisRendererX.setLabel(new Label("Logarithmic axis"));
plot.setAxisRenderer(XYPlot.AXIS_X, axisRendererX);
// Custom tick labels
Map<Double, String> labels = new HashMap<>();
labels.put(2.0, "Two");
labels.put(1.5, "OnePointFive");
axisRendererX.setCustomTicks(labels);
// Custom stroke for the x-axis
BasicStroke stroke = new BasicStroke(2f);
axisRendererX.setShapeStroke(stroke);
Label linearAxisLabel = new Label("Linear axis");
linearAxisLabel.setRotation(90);
axisRendererY.setLabel(linearAxisLabel);
// Change intersection point of Y axis
axisRendererY.setIntersection(1.0);
// Change tick spacing
axisRendererX.setTickSpacing(2.0);
// Format rendering of data points
PointRenderer sizeablePointRenderer = new SizeablePointRenderer();
sizeablePointRenderer.setColor(GraphicsUtils.deriveDarker(COLOR1));
plot.setPointRenderers(seriesLin, sizeablePointRenderer);
PointRenderer defaultPointRenderer = new DefaultPointRenderer2D();
defaultPointRenderer.setColor(GraphicsUtils.deriveDarker(COLOR2));
defaultPointRenderer.setErrorVisible(true);
defaultPointRenderer.setErrorColor(COLOR2);
plot.setPointRenderers(seriesLog, defaultPointRenderer);
// Format data lines
DiscreteLineRenderer2D discreteRenderer = new DiscreteLineRenderer2D();
discreteRenderer.setColor(COLOR1);
discreteRenderer.setStroke(new BasicStroke(
3.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND,
10.0f, new float[] {3f, 6f}, 0.0f));
plot.setLineRenderers(seriesLin, discreteRenderer);
// Custom gaps for points
discreteRenderer.setGap(2.0);
discreteRenderer.setGapRounded(true);
// Custom ascending
discreteRenderer.setAscentDirection(Orientation.VERTICAL);
discreteRenderer.setAscendingPoint(0.5);
// Add plot to Swing component
add(new InteractivePanel(plot), BorderLayout.CENTER);
}
示例12: SpiralPlot
import de.erichseifert.gral.data.DataSeries; //导入依赖的package包/类
@SuppressWarnings("unchecked")
public SpiralPlot() {
setPreferredSize(new Dimension(600, 600));
// Generate data
DataTable data = new DataTable(Double.class, Double.class, Double.class);
for (double alpha = 0.0, r = 0.0; r <= 10.0; alpha -= 1.0, r += 0.05) {
double x = r*Math.cos(alpha);
double y = r*Math.sin(alpha);
double z = 3.0 + 4.0*r;
data.add(x, y, z);
}
// Create a new data series (optional)
DataSeries series = new DataSeries("Spiral", data);
// Create a new xy-plot
XYPlot plot = new XYPlot(series);
// Format plot
plot.setInsets(new Insets2D.Double(40.0)); // Add a margin to the plot
plot.setBackground(new Color(0.75f, 0.75f, 0.75f));
// Format plot area
XYPlotArea2D plotArea = (XYPlotArea2D) plot.getPlotArea();
plotArea.setBorderColor(null); // Remove border of plot area
plotArea.setMajorGridX(false); // Disable vertical grid
plotArea.setMajorGridY(false); // Disable horizontal grid
plotArea.setClippingArea(null); // Disable clipping
// Format axes
plot.getAxisRenderer(XYPlot.AXIS_X).setShapeVisible(false); // Disable x axis
plot.getAxisRenderer(XYPlot.AXIS_X).setTicksVisible(false); // Disable tick marks on x axis
plot.getAxisRenderer(XYPlot.AXIS_Y).setShapeVisible(false); // Disable y axis
plot.getAxisRenderer(XYPlot.AXIS_Y).setTicksVisible(false); // Disable tick marks on y axis
plot.getAxis(XYPlot.AXIS_X).setRange(-10.0, 10.0); // Scale x axis from -10 to 10
plot.getAxis(XYPlot.AXIS_Y).setRange(-10.0, 10.0); // Scale y axis from -10 to 10
// Format data series
Color color = GraphicsUtils.deriveWithAlpha(COLOR1, 96);
SizeablePointRenderer pointRenderer = new SizeablePointRenderer();
pointRenderer.setShape(new Ellipse2D.Double(-0.5, -0.5, 1.0, 1.0)); // shape of data points
pointRenderer.setColor(color); // color of data points
pointRenderer.setColumn(2); // data column which determines the scaling of data point shapes
plot.setPointRenderers(series, pointRenderer); // Assign the point renderer to the data series
add(new InteractivePanel(plot), BorderLayout.CENTER); // Add the plot to the Swing component
}
示例13: ConvolutionExample
import de.erichseifert.gral.data.DataSeries; //导入依赖的package包/类
@SuppressWarnings("unchecked")
public ConvolutionExample() {
// Generate 200 data points
DataTable data = new DataTable(Double.class, Double.class);
Random r = new Random();
for (int i = 0; i < SAMPLE_COUNT; i++) {
double x = i/2.0/Math.PI;
double yError = Math.sqrt(3.0*0.1)*r.nextGaussian();
double y = 10.0*Math.sin(x/5.0) + yError*yError*yError;
data.add(x, y);
}
DataSeries ds = new DataSeries("Data", data, 0, 1);
final double KERNEL_VARIANCE = 5.0;
// Create a smoothed data series from a binomial (near-gaussian) convolution filter
Kernel kernelLowpass = Kernel.getBinomial(KERNEL_VARIANCE).normalize();
Filter2D dataLowpass = new Convolution(data, kernelLowpass, Filter2D.Mode.REPEAT, 1);
DataSeries dsLowpass = new DataSeries("Lowpass", dataLowpass, 0, 1);
// Create a derived data series from a binomial convolution filter
Kernel kernelHighpass = Kernel.getBinomial(KERNEL_VARIANCE).normalize().negate().add(new Kernel(1.0));
Filter2D dataHighpass = new Convolution(data, kernelHighpass, Filter2D.Mode.REPEAT, 1);
DataSeries dsHighpass = new DataSeries("Highpass", dataHighpass, 0, 1);
// Create a new data series that calculates the moving average using a custom convolution kernel
int kernelMovingAverageSize = (int)Math.round(4.0*KERNEL_VARIANCE);
Kernel kernelMovingAverage = Kernel.getUniform(kernelMovingAverageSize, kernelMovingAverageSize - 1, 1.0).normalize();
Filter2D dataMovingAverage = new Convolution(data, kernelMovingAverage, Filter2D.Mode.OMIT, 1);
DataSeries dsMovingAverage = new DataSeries("Moving Average", dataMovingAverage, 0, 1);
// Create a new data series that calculates the moving median
int kernelMovingMedianSize = (int)Math.round(4.0*KERNEL_VARIANCE);
Filter2D dataMovingMedian = new Median(data, kernelMovingMedianSize, kernelMovingMedianSize - 1, Filter2D.Mode.OMIT, 1);
DataSeries dsMovingMedian = new DataSeries("Moving Median", dataMovingMedian, 0, 1);
// Create a new xy-plot
XYPlot plot = new XYPlot(ds, dsLowpass, dsHighpass, dsMovingAverage, dsMovingMedian);
// Format plot
plot.setInsets(new Insets2D.Double(20.0, 40.0, 40.0, 40.0));
plot.setLegendVisible(true);
// Format legend
plot.getLegend().setOrientation(Orientation.HORIZONTAL);
plot.getLegend().setAlignmentY(1.0);
// Format data series as lines of different colors
formatLine(plot, ds, Color.BLACK);
formatLine(plot, dsLowpass, COLOR1);
formatLine(plot, dsHighpass, GraphicsUtils.deriveDarker(COLOR1));
formatLine(plot, dsMovingAverage, COLOR2);
formatLine(plot, dsMovingMedian, GraphicsUtils.deriveDarker(COLOR2));
// Add plot to Swing component
add(new InteractivePanel(plot), BorderLayout.CENTER);
}
示例14: formatLine
import de.erichseifert.gral.data.DataSeries; //导入依赖的package包/类
private static void formatLine(XYPlot plot, DataSeries series, Color color) {
plot.setPointRenderers(series, null);
DefaultLineRenderer2D line = new DefaultLineRenderer2D();
line.setColor(color);
plot.setLineRenderers(series, line);
}
示例15: SimpleXYPlot
import de.erichseifert.gral.data.DataSeries; //导入依赖的package包/类
@SuppressWarnings("unchecked")
public SimpleXYPlot() {
// Generate data
DataTable data = new DataTable(Double.class, Double.class, Double.class,
Double.class, Double.class, Double.class);
for (double x = 1.0; x <= 400.0; x *= 1.5) {
double x2 = x/5.0;
data.add(x2, -Math.sqrt(x2) + 5.0, 5.0*Math.log10(x2),
random.nextDouble() + 1.0, random.nextDouble() + 0.5, 1.0 + 2.0*random.nextDouble());
}
// Create data series
DataSeries seriesLog = new DataSeries(data, 0, 2, 3, 4);
DataSeries seriesLin = new DataSeries(data, 0, 1, 5);
// Create new xy-plot
XYPlot plot = new XYPlot(seriesLog, seriesLin);
// Format plot
plot.setInsets(new Insets2D.Double(20.0, 40.0, 40.0, 40.0));
plot.setBackground(Color.WHITE);
plot.getTitle().setText(getDescription());
// Format plot area
plot.getPlotArea().setBackground(new RadialGradientPaint(
new Point2D.Double(0.5, 0.5),
0.75f,
new float[] { 0.6f, 0.8f, 1.0f },
new Color[] { new Color(0, 0, 0, 0), new Color(0, 0, 0, 32), new Color(0, 0, 0, 128) }
));
plot.getPlotArea().setBorderStroke(null);
// Format axes
AxisRenderer axisRendererX = new LogarithmicRenderer2D();
AxisRenderer axisRendererY = plot.getAxisRenderer(XYPlot.AXIS_Y);
axisRendererX.setLabel("Logarithmic axis");
plot.setAxisRenderer(XYPlot.AXIS_X, axisRendererX);
// Custom tick labels
Map<Double, String> labels = new HashMap<Double, String>();
labels.put(2.0, "Two");
labels.put(1.5, "OnePointFive");
axisRendererX.setCustomTicks(labels);
// Custom stroke for the x-axis
BasicStroke stroke = new BasicStroke(2f);
axisRendererX.setShapeStroke(stroke);
axisRendererY.setLabel("Linear axis");
// Change intersection point of Y axis
axisRendererY.setIntersection(1.0);
// Change tick spacing
axisRendererX.setTickSpacing(2.0);
// Format rendering of data points
PointRenderer sizeablePointRenderer = new SizeablePointRenderer();
sizeablePointRenderer.setColor(GraphicsUtils.deriveDarker(COLOR1));
plot.setPointRenderer(seriesLin, sizeablePointRenderer);
PointRenderer defaultPointRenderer = new DefaultPointRenderer2D();
defaultPointRenderer.setColor(GraphicsUtils.deriveDarker(COLOR2));
defaultPointRenderer.setErrorVisible(true);
defaultPointRenderer.setErrorColor(COLOR2);
plot.setPointRenderer(seriesLog, defaultPointRenderer);
// Format data lines
DiscreteLineRenderer2D discreteRenderer = new DiscreteLineRenderer2D();
discreteRenderer.setColor(COLOR1);
discreteRenderer.setStroke(new BasicStroke(
3.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND,
10.0f, new float[] {3f, 6f}, 0.0f));
plot.setLineRenderer(seriesLin, discreteRenderer);
// Custom gaps for points
discreteRenderer.setGap(2.0);
discreteRenderer.setGapRounded(true);
// Custom ascending
discreteRenderer.setAscentDirection(Orientation.VERTICAL);
discreteRenderer.setAscendingPoint(0.5);
// Add plot to Swing component
add(new InteractivePanel(plot), BorderLayout.CENTER);
}