Skip to content

Commit 0f58ac2

Browse files
maarztctrueden
authored andcommitted
Add demos on how to display plots
1 parent a3523da commit 0f58ac2

File tree

9 files changed

+638
-0
lines changed

9 files changed

+638
-0
lines changed
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/*
2+
* #%L
3+
* ImageJ software for multidimensional image processing and analysis.
4+
* %%
5+
* Copyright (C) 2009 - 2016 Board of Regents of the University of
6+
* Wisconsin-Madison, Broad Institute of MIT and Harvard, and Max Planck
7+
* Institute of Molecular Cell Biology and Genetics.
8+
* %%
9+
* Redistribution and use in source and binary forms, with or without
10+
* modification, are permitted provided that the following conditions are met:
11+
*
12+
* 1. Redistributions of source code must retain the above copyright notice,
13+
* this list of conditions and the following disclaimer.
14+
* 2. Redistributions in binary form must reproduce the above copyright notice,
15+
* this list of conditions and the following disclaimer in the documentation
16+
* and/or other materials provided with the distribution.
17+
*
18+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19+
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20+
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21+
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
22+
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23+
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24+
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25+
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26+
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27+
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28+
* POSSIBILITY OF SUCH DAMAGE.
29+
* #L%
30+
*/
31+
32+
package org.scijava.ui.swing.viewer.plot;
33+
34+
/**
35+
* @author Matthias Arzt
36+
*/
37+
public class AllDemos {
38+
39+
public static void main(final String... args) {
40+
new BoxPlotDemo().run();
41+
new CategoryChartDemo().run();
42+
new LineStyleDemo().run();
43+
new LogarithmicAxisDemo().run();
44+
new MarkerStyleDemo().run();
45+
new SortingCategoriesDemo().run();
46+
new XYPlotDemo().run();
47+
}
48+
49+
}
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
/*
2+
* #%L
3+
* ImageJ software for multidimensional image processing and analysis.
4+
* %%
5+
* Copyright (C) 2009 - 2016 Board of Regents of the University of
6+
* Wisconsin-Madison, Broad Institute of MIT and Harvard, and Max Planck
7+
* Institute of Molecular Cell Biology and Genetics.
8+
* %%
9+
* Redistribution and use in source and binary forms, with or without
10+
* modification, are permitted provided that the following conditions are met:
11+
*
12+
* 1. Redistributions of source code must retain the above copyright notice,
13+
* this list of conditions and the following disclaimer.
14+
* 2. Redistributions in binary form must reproduce the above copyright notice,
15+
* this list of conditions and the following disclaimer in the documentation
16+
* and/or other materials provided with the distribution.
17+
*
18+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19+
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20+
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21+
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
22+
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23+
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24+
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25+
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26+
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27+
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28+
* POSSIBILITY OF SUCH DAMAGE.
29+
* #L%
30+
*/
31+
32+
package org.scijava.ui.swing.viewer.plot;
33+
34+
import org.scijava.plot.BoxSeries;
35+
import org.scijava.plot.CategoryChart;
36+
import org.scijava.util.Colors;
37+
38+
import java.util.*;
39+
40+
/**
41+
* @author Matthias Arzt
42+
*/
43+
class BoxPlotDemo extends ChartDemo{
44+
45+
public void run() {
46+
CategoryChart chart = plotService.newCategoryChart();
47+
48+
Map<String, Collection<Double>> randomData1 = new TreeMap<>();
49+
randomData1.put("A", collectionOfRandomNumbers(10));
50+
randomData1.put("B", collectionOfRandomNumbers(20));
51+
randomData1.put("C", collectionOfRandomNumbers(30));
52+
53+
BoxSeries boxSeries1 = chart.addBoxSeries();
54+
boxSeries1.setLabel("boxes1");
55+
boxSeries1.setValues(randomData1);
56+
boxSeries1.setColor(Colors.CYAN);
57+
58+
Map<String, Collection<Double>> randomData2 = new TreeMap<>();
59+
randomData2.put("A", collectionOfRandomNumbers(10));
60+
randomData2.put("B", collectionOfRandomNumbers(20));
61+
randomData2.put("C", collectionOfRandomNumbers(30));
62+
63+
BoxSeries boxSeries2 = chart.addBoxSeries();
64+
boxSeries2.setLabel("boxes2");
65+
boxSeries2.setValues(randomData2);
66+
boxSeries2.setColor(Colors.BLACK);
67+
68+
ui.show(chart);
69+
}
70+
71+
private static Collection<Double> collectionOfRandomNumbers(int size) {
72+
Random rand = new Random();
73+
Vector<Double> result = new Vector<>(size);
74+
for(int i = 0; i < size; i++)
75+
result.add(rand.nextGaussian()*20);
76+
return result;
77+
}
78+
79+
public static void main(final String... args) {
80+
new BoxPlotDemo().run();
81+
}
82+
}
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
/*
2+
* #%L
3+
* ImageJ software for multidimensional image processing and analysis.
4+
* %%
5+
* Copyright (C) 2009 - 2016 Board of Regents of the University of
6+
* Wisconsin-Madison, Broad Institute of MIT and Harvard, and Max Planck
7+
* Institute of Molecular Cell Biology and Genetics.
8+
* %%
9+
* Redistribution and use in source and binary forms, with or without
10+
* modification, are permitted provided that the following conditions are met:
11+
*
12+
* 1. Redistributions of source code must retain the above copyright notice,
13+
* this list of conditions and the following disclaimer.
14+
* 2. Redistributions in binary form must reproduce the above copyright notice,
15+
* this list of conditions and the following disclaimer in the documentation
16+
* and/or other materials provided with the distribution.
17+
*
18+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19+
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20+
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21+
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
22+
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23+
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24+
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25+
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26+
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27+
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28+
* POSSIBILITY OF SUCH DAMAGE.
29+
* #L%
30+
*/
31+
32+
package org.scijava.ui.swing.viewer.plot;
33+
34+
import org.scijava.plot.BarSeries;
35+
import org.scijava.plot.CategoryChart;
36+
import org.scijava.plot.LineSeries;
37+
38+
import java.util.Arrays;
39+
import java.util.HashMap;
40+
import java.util.Map;
41+
42+
/**
43+
* @author Matthias Arzt
44+
*/
45+
class CategoryChartDemo extends ChartDemo{
46+
47+
public void run() {
48+
49+
CategoryChart chart = plotService.newCategoryChart();
50+
chart.categoryAxis().setManualCategories(Arrays.asList("one wheel", "bicycle", "car"));
51+
52+
Map<String, Double> wheelsData = new HashMap<>();
53+
wheelsData.put("one wheel", 1.0);
54+
wheelsData.put("bicycle", 2.0);
55+
wheelsData.put("car", 4.0);
56+
57+
LineSeries lineSeries = chart.addLineSeries();
58+
lineSeries.setLabel("wheels");
59+
lineSeries.setValues(wheelsData);
60+
61+
Map<String, Double> speedData = new HashMap<>();
62+
speedData.put("one wheel", 10.0);
63+
speedData.put("bicycle", 30.0);
64+
speedData.put("car", 200.0);
65+
66+
BarSeries barSeries = chart.addBarSeries();
67+
barSeries.setLabel("speed");
68+
barSeries.setValues(speedData);
69+
70+
ui.show(chart);
71+
}
72+
73+
public static void main(final String... args) {
74+
new CategoryChartDemo().run();
75+
}
76+
}
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
/*
2+
* #%L
3+
* ImageJ software for multidimensional image processing and analysis.
4+
* %%
5+
* Copyright (C) 2009 - 2016 Board of Regents of the University of
6+
* Wisconsin-Madison, Broad Institute of MIT and Harvard, and Max Planck
7+
* Institute of Molecular Cell Biology and Genetics.
8+
* %%
9+
* Redistribution and use in source and binary forms, with or without
10+
* modification, are permitted provided that the following conditions are met:
11+
*
12+
* 1. Redistributions of source code must retain the above copyright notice,
13+
* this list of conditions and the following disclaimer.
14+
* 2. Redistributions in binary form must reproduce the above copyright notice,
15+
* this list of conditions and the following disclaimer in the documentation
16+
* and/or other materials provided with the distribution.
17+
*
18+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19+
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20+
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21+
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
22+
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23+
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24+
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25+
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26+
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27+
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28+
* POSSIBILITY OF SUCH DAMAGE.
29+
* #L%
30+
*/
31+
32+
package org.scijava.ui.swing.viewer.plot;
33+
34+
import org.scijava.Context;
35+
import org.scijava.plot.PlotService;
36+
import org.scijava.plugin.Parameter;
37+
import org.scijava.ui.UIService;
38+
39+
/**
40+
* @author Matthias Arzt
41+
*/
42+
class ChartDemo {
43+
44+
@Parameter
45+
public UIService ui;
46+
47+
@Parameter
48+
public PlotService plotService;
49+
50+
ChartDemo() {
51+
new Context().inject( this );
52+
}
53+
54+
}
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
/*
2+
* #%L
3+
* ImageJ software for multidimensional image processing and analysis.
4+
* %%
5+
* Copyright (C) 2009 - 2016 Board of Regents of the University of
6+
* Wisconsin-Madison, Broad Institute of MIT and Harvard, and Max Planck
7+
* Institute of Molecular Cell Biology and Genetics.
8+
* %%
9+
* Redistribution and use in source and binary forms, with or without
10+
* modification, are permitted provided that the following conditions are met:
11+
*
12+
* 1. Redistributions of source code must retain the above copyright notice,
13+
* this list of conditions and the following disclaimer.
14+
* 2. Redistributions in binary form must reproduce the above copyright notice,
15+
* this list of conditions and the following disclaimer in the documentation
16+
* and/or other materials provided with the distribution.
17+
*
18+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19+
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20+
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21+
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
22+
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23+
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24+
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25+
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26+
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27+
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28+
* POSSIBILITY OF SUCH DAMAGE.
29+
* #L%
30+
*/
31+
32+
package org.scijava.ui.swing.viewer.plot;
33+
34+
import org.scijava.plot.LineStyle;
35+
import org.scijava.plot.MarkerStyle;
36+
import org.scijava.plot.XYPlot;
37+
import org.scijava.plot.XYSeries;
38+
import org.scijava.util.Colors;
39+
40+
import java.util.Arrays;
41+
42+
/**
43+
* @author Matthias Arzt
44+
*/
45+
class LineStyleDemo extends ChartDemo {
46+
47+
48+
public void run() {
49+
LineStyle[] lineStyles = LineStyle.values();
50+
51+
XYPlot plot = plotService.newXYPlot();
52+
plot.setTitle("Line Styles");
53+
plot.xAxis().setManualRange(-1.0, 2.0);
54+
plot.yAxis().setManualRange(-1.0, (double) lineStyles.length);
55+
56+
for(int i = 0; i < lineStyles.length; i++)
57+
addSeries(plot, i, lineStyles[i]);
58+
59+
ui.show(plot);
60+
}
61+
62+
private void addSeries(XYPlot plot, double y, LineStyle lineStyle) {
63+
XYSeries series = plot.addXYSeries();
64+
series.setLabel(lineStyle.toString());
65+
series.setValues(Arrays.asList(0.0,1.0), Arrays.asList(y,y));
66+
series.setStyle(plotService.newSeriesStyle(Colors.BLACK, lineStyle, MarkerStyle.CIRCLE));
67+
}
68+
69+
public static void main(final String... args) {
70+
new LineStyleDemo().run();
71+
}
72+
73+
}

0 commit comments

Comments
 (0)