├── .travis.yml
├── LICENSE
├── README.md
├── dist
└── jmathplot.jar
├── doc
├── css
│ ├── maven-base.css
│ ├── maven-theme.css
│ ├── print.css
│ └── site.css
├── dependencies.html
├── images
│ ├── close.gif
│ ├── collapsed.gif
│ ├── expanded.gif
│ ├── external.png
│ ├── icon_error_sml.gif
│ ├── icon_info_sml.gif
│ ├── icon_success_sml.gif
│ ├── icon_warning_sml.gif
│ ├── logos
│ │ ├── build-by-maven-black.png
│ │ ├── build-by-maven-white.png
│ │ └── maven-feather.png
│ └── newwindow.png
├── index.html
├── integration.html
├── issue-tracking.html
├── license.html
├── mail-lists.html
├── plugin-management.html
├── plugins.html
├── project-info.html
├── project-summary.html
├── source-repository.html
└── team-list.html
├── examples
├── CommandLineInterface.md
├── CustomPlotExample.md
├── GridPlotsExample.md
├── HistogramExample.md
└── LinePlotExample.md
├── pom.xml
└── src
├── main
├── java
│ └── org
│ │ └── math
│ │ └── plot
│ │ ├── DataPanel.java
│ │ ├── DataSelectPanel.java
│ │ ├── DataSelectTable.java
│ │ ├── FrameView.java
│ │ ├── MatrixTablePanel.java
│ │ ├── ParametersPanel.java
│ │ ├── Plot2DPanel.java
│ │ ├── Plot3DPanel.java
│ │ ├── PlotPanel.java
│ │ ├── canvas
│ │ ├── Plot2DCanvas.java
│ │ ├── Plot3DCanvas.java
│ │ └── PlotCanvas.java
│ │ ├── components
│ │ ├── DataFrame.java
│ │ ├── DataToolBar.java
│ │ ├── DatasFrame.java
│ │ ├── LegendPanel.java
│ │ ├── PlotToolBar.java
│ │ └── ScalesFrame.java
│ │ ├── plotObjects
│ │ ├── Axis.java
│ │ ├── Base.java
│ │ ├── BaseDependant.java
│ │ ├── BaseLabel.java
│ │ ├── BaseLine.java
│ │ ├── BasePlot.java
│ │ ├── Editable.java
│ │ ├── Label.java
│ │ ├── Line.java
│ │ ├── Noteable.java
│ │ ├── PaintImage.java
│ │ ├── Plotable.java
│ │ └── RasterImage.java
│ │ ├── plots
│ │ ├── BarPlot.java
│ │ ├── BoxPlot2D.java
│ │ ├── BoxPlot3D.java
│ │ ├── CloudPlot2D.java
│ │ ├── CloudPlot3D.java
│ │ ├── DensityLayerPlot.java
│ │ ├── GaussianDensityLayerPlot.java
│ │ ├── GridPlot3D.java
│ │ ├── HistogramPlot2D.java
│ │ ├── HistogramPlot3D.java
│ │ ├── LayerPlot.java
│ │ ├── LinePlot.java
│ │ ├── Plot.java
│ │ ├── QuantileLayerPlot.java
│ │ ├── ScatterPlot.java
│ │ ├── StaircasePlot.java
│ │ └── VectorLayerPlot.java
│ │ ├── render
│ │ ├── AWTDrawer.java
│ │ ├── AWTDrawer2D.java
│ │ ├── AWTDrawer3D.java
│ │ ├── AbstractDrawer.java
│ │ ├── Projection.java
│ │ ├── Projection2D.java
│ │ └── Projection3D.java
│ │ └── utils
│ │ ├── Array.java
│ │ ├── FastMath.java
│ │ ├── Histogram.java
│ │ └── NumbersUtils.java
└── resources
│ └── org
│ └── math
│ └── plot
│ └── icons
│ ├── adjustbounds.png
│ ├── back.png
│ ├── center.png
│ ├── data.png
│ ├── edit.png
│ ├── noadjustbounds.png
│ ├── position.png
│ ├── rotation.png
│ ├── scale.png
│ ├── toclipboard.png
│ ├── tofile.png
│ ├── topngfile.png
│ └── zoom.png
└── test
└── resources
└── TestApplet.html
/.travis.yml:
--------------------------------------------------------------------------------
1 | language: java
2 | jdk:
3 | - oraclejdk8
4 | install: mvn install -DskipTests=true -Dgpg.skip=true
5 | script: "mvn cobertura:cobertura"
6 | after_success:
7 | - bash <(curl -s https://codecov.io/bash)
8 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | BSD 2-Clause License
2 |
3 | Copyright (c) 2021, Yann Richet
4 | All rights reserved.
5 |
6 | Redistribution and use in source and binary forms, with or without
7 | modification, are permitted provided that the following conditions are met:
8 |
9 | 1. Redistributions of source code must retain the above copyright notice, this
10 | list of conditions and the following disclaimer.
11 |
12 | 2. Redistributions in binary form must reproduce the above copyright notice,
13 | this list of conditions and the following disclaimer in the documentation
14 | and/or other materials provided with the distribution.
15 |
16 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
20 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
22 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
23 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
24 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
25 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | [](https://maven-badges.herokuapp.com/maven-central/com.github.yannrichet/JMathPlot)
2 | [](https://travis-ci.org/yannrichet/jmathplot)
3 | [](https://codecov.io/gh/yannrichet/jmathplot)
4 |
5 | # JMathPlot: interactive 2D and 3D plots
6 |
7 | Provides interactive 2D/3D plot (without openGL) :
8 |
9 | 2D/3D scatter plot
10 | 2D/3D line plot
11 | 2D staircase plot
12 | 2D/3D histogram plot
13 | 2D/3D boxplot
14 | 3D grid plot
15 | 2D/3D quantiles on plots
16 |
17 | Note: for a true OpenGL java plot library, try the good jzy3d project
18 |
19 | ## Example Java code ##
20 |
21 | ```java
22 | import org.math.plot.*;
23 | ...
24 |
25 | double[] x = ...
26 | double[] y = ...
27 |
28 | // create your PlotPanel (you can use it as a JPanel)
29 | Plot2DPanel plot = new Plot2DPanel();
30 |
31 | // add a line plot to the PlotPanel
32 | plot.addLinePlot("my plot", x, y);
33 |
34 | // put the PlotPanel in a JFrame, as a JPanel
35 | JFrame frame = new JFrame("a plot panel");
36 | frame.setContentPane(plot);
37 | frame.setVisible(true);
38 | ```
39 |
40 | ## Use it ##
41 |
42 | Put https://github.com/yannrichet/jmathplot/blob/master/dist/jmathplot.jar in your java classpath
43 |
44 | Or include maven dependency:
45 | ```xml
46 |
GroupId | ArtifactId | Version |
---|---|---|
org.apache.maven.plugins | maven-antrun-plugin | 1.7 |
org.apache.maven.plugins | maven-assembly-plugin | 2.2-beta-4 |
org.apache.maven.plugins | maven-clean-plugin | 2.5 |
org.apache.maven.plugins | maven-compiler-plugin | 2.5.1 |
org.apache.maven.plugins | maven-dependency-plugin | 2.4 |
org.apache.maven.plugins | maven-deploy-plugin | 2.4 |
org.apache.maven.plugins | maven-ear-plugin | 2.3.2 |
org.apache.maven.plugins | maven-ejb-plugin | 2.2 |
org.apache.maven.plugins | maven-install-plugin | 2.4 |
org.apache.maven.plugins | maven-jar-plugin | 2.3.2 |
org.apache.maven.plugins | maven-javadoc-plugin | 2.9.1 |
org.apache.maven.plugins | maven-plugin-plugin | 3.2 |
org.apache.maven.plugins | maven-rar-plugin | 2.2 |
org.apache.maven.plugins | maven-release-plugin | 2.1 |
org.apache.maven.plugins | maven-resources-plugin | 2.3 |
org.apache.maven.plugins | maven-site-plugin | 2.1 |
org.apache.maven.plugins | maven-source-plugin | 2.2.1 |
org.apache.maven.plugins | maven-surefire-plugin | 2.10 |
org.apache.maven.plugins | maven-war-plugin | 2.1.1 |
GroupId | ArtifactId | Version |
---|---|---|
org.apache.maven.plugins | maven-compiler-plugin | 2.5.1 |
org.apache.maven.plugins | maven-enforcer-plugin | 1.2 |
org.apache.maven.plugins | maven-install-plugin | 2.5.2 |
org.apache.maven.plugins | maven-jar-plugin | 2.5 |
org.apache.maven.plugins | maven-release-plugin | 2.4.2 |
This document provides an overview of the various documents and links that are part of this project's general information. All of this content is automatically generated by Maven on behalf of the project.
Document | Description |
---|---|
Project License | This is a link to the definitions of project licenses. |
Mailing Lists | This document provides subscription and archive information for this project's mailing lists. |
Plugin Management | This document lists the plugins that are defined through pluginManagement. |
Project Plugins | This document lists the build plugins and the report plugins used by this project. |
Continuous Integration | This is a link to the definitions of all continuous integration processes that builds and tests code on a frequent, regular basis. |
Source Repository | This is a link to the online source repository that can be viewed via a web browser. |
About | Sonatype helps open source projects to set up Maven repositories on https://oss.sonatype.org/ |
Issue Tracking | This is a link to the issue management system for this project. Issues (bugs, features, change requests) can be created and queried using this link. |
Project Team | This document provides information on the members of this project. These are the individuals who have contributed to the project in one form or another. |
Project Summary | This document lists other related information of this project |
Dependencies | This document lists the project's dependencies and provides information on each dependency. |
Field | Value |
---|---|
Name | jmathplot |
Description | Sonatype helps open source projects to set up Maven repositories on https://oss.sonatype.org/ |
Homepage | https://github.com/yannrichet/jmathplot |
Refer to the documentation of the SCM used for more information about anonymously check out. The connection url is:
git:git@github.com:yannrichet/jmathplot.git
A successful project requires many people to play many roles. Some members write code or documentation, while others are valuable as testers, submitting patches and suggestions.
The team is comprised of Members and Contributors. Members have direct access to the source of a project and actively evolve the code-base. Contributors improve the project through submission of patches and suggestions to the Members. The number of Contributors to the project is unbounded. Get involved today. All contributions to the project are greatly appreciated.
serialVersionUID
20 | */
21 | private static final long serialVersionUID = 1L;
22 |
23 | protected JButton buttonPasteToClipboard;
24 |
25 | protected JButton buttonSaveFile;
26 |
27 | private boolean denySaveSecurity;
28 |
29 | private JFileChooser fileChooser;
30 |
31 | private DataPanel dataPanel;
32 |
33 | public DataToolBar(DataPanel dp) {
34 |
35 | dataPanel = dp;
36 |
37 | try {
38 | fileChooser = new JFileChooser();
39 | } catch (AccessControlException ace) {
40 | denySaveSecurity = true;
41 | }
42 |
43 | buttonPasteToClipboard = new JButton(new ImageIcon(org.math.plot.PlotPanel.class.getResource("icons/toclipboard.png")));
44 | buttonPasteToClipboard.setToolTipText("Copy data to clipboard");
45 |
46 | buttonSaveFile = new JButton(new ImageIcon(org.math.plot.PlotPanel.class.getResource("icons/tofile.png")));
47 | buttonSaveFile.setToolTipText("Save data into ASCII file");
48 |
49 | buttonPasteToClipboard.addActionListener(new ActionListener() {
50 | public void actionPerformed(ActionEvent e) {
51 | dataPanel.toClipBoard();
52 | }
53 | });
54 | buttonSaveFile.addActionListener(new ActionListener() {
55 | public void actionPerformed(ActionEvent e) {
56 | chooseFile();
57 | }
58 | });
59 |
60 | add(buttonPasteToClipboard, null);
61 | add(buttonSaveFile, null);
62 |
63 | if (!denySaveSecurity) {
64 | fileChooser.addActionListener(new java.awt.event.ActionListener() {
65 | public void actionPerformed(ActionEvent e) {
66 | saveFile();
67 | }
68 | });
69 | } else {
70 | buttonSaveFile.setEnabled(false);
71 | }
72 | }
73 |
74 | void saveFile() {
75 | java.io.File file = fileChooser.getSelectedFile();
76 | dataPanel.toASCIIFile(file);
77 | }
78 |
79 | void chooseFile() {
80 | fileChooser.showSaveDialog(this);
81 | }
82 |
83 | }
--------------------------------------------------------------------------------
/src/main/java/org/math/plot/components/DatasFrame.java:
--------------------------------------------------------------------------------
1 | package org.math.plot.components;
2 |
3 | import java.awt.*;
4 | import java.awt.event.*;
5 |
6 | import javax.swing.*;
7 | import javax.swing.event.*;
8 |
9 | import org.math.plot.*;
10 | import org.math.plot.canvas.*;
11 | import org.math.plot.plots.*;
12 |
13 | /**
14 | * BSD License
15 | *
16 | * @author Yann RICHET
17 | */
18 |
19 | public class DatasFrame extends JFrame {
20 |
21 | private static final long serialVersionUID = 1L;
22 |
23 | private PlotCanvas plotCanvas;
24 |
25 | private LegendPanel legend;
26 |
27 | public JTabbedPane panels;
28 |
29 | public DatasFrame(PlotCanvas p, LegendPanel l) {
30 | super("Data");
31 | plotCanvas = p;
32 | legend = l;
33 | JPanel panel = new JPanel();
34 | panels = new JTabbedPane();
35 |
36 | for (Plot plot: plotCanvas.getPlots())
37 | panels.add(new DataPanel(/*this, */plot), plot.getName());
38 |
39 |
40 | panel.add(panels);
41 | setContentPane(panel);
42 | pack();
43 | setVisible(true);
44 | }
45 |
46 | public class DataPanel extends JPanel {
47 |
48 | private static final long serialVersionUID = 1L;
49 |
50 | MatrixTablePanel XY;
51 |
52 | JCheckBox visible;
53 |
54 | JButton color;
55 |
56 | JPanel plottoolspanel;
57 |
58 | Plot plot;
59 |
60 | DatasFrame dframe;
61 |
62 | public DataPanel(/*DatasFrame _dframe,*/Plot _plot) {
63 | plot = _plot;
64 | //dframe = _dframe;
65 | visible = new JCheckBox("visible");
66 | visible.setSelected(plot.getVisible());
67 | color = new JButton();
68 | color.setBackground(plot.getColor());
69 | XY = new MatrixTablePanel( plotCanvas.reverseMapedData( plot.getData()));
70 |
71 | visible.addChangeListener(new ChangeListener() {
72 | public void stateChanged(ChangeEvent e) {
73 | if (visible.isSelected())
74 | plot.setVisible(true);
75 | else
76 | plot.setVisible(false);
77 | /*dframe.*/plotCanvas.repaint();
78 | }
79 | });
80 | color.addActionListener(new ActionListener() {
81 | public void actionPerformed(ActionEvent e) {
82 | Color c = JColorChooser.showDialog(plotCanvas, "Choose plot color", plot.getColor());
83 | color.setBackground(c);
84 | plot.setColor(c);
85 | legend.updateLegends();
86 | /*dframe.*/plotCanvas.linkedLegendPanel.repaint();
87 | /*dframe.*/plotCanvas.repaint();
88 | }
89 | });
90 |
91 | this.setLayout(new BorderLayout());
92 | plottoolspanel = new JPanel();
93 | plottoolspanel.add(visible);
94 | plottoolspanel.add(color);
95 | this.add(plottoolspanel, BorderLayout.NORTH);
96 | this.add(XY, BorderLayout.CENTER);
97 | }
98 | }
99 | }
--------------------------------------------------------------------------------
/src/main/java/org/math/plot/plotObjects/BaseDependant.java:
--------------------------------------------------------------------------------
1 | package org.math.plot.plotObjects;
2 |
3 | /**
4 | * BSD License
5 | *
6 | * @author Yann RICHET
7 | */
8 |
9 | public interface BaseDependant {
10 | public void resetBase();
11 | }
--------------------------------------------------------------------------------
/src/main/java/org/math/plot/plotObjects/BaseLabel.java:
--------------------------------------------------------------------------------
1 | package org.math.plot.plotObjects;
2 |
3 | import java.awt.*;
4 |
5 | import org.math.plot.*;
6 | import org.math.plot.canvas.*;
7 | import org.math.plot.render.*;
8 |
9 | /**
10 | * BSD License
11 | *
12 | * @author Yann RICHET
13 | */
14 |
15 | public class BaseLabel extends Label /* implements BaseDependant */{
16 |
17 | public BaseLabel(String l, Color c, double... rC) {
18 | super(l, c, rC);
19 | }
20 |
21 | /*
22 | * public void resetBase() { System.out.println("BaseLabel.resetBase"); }
23 | */
24 |
25 | public static void main(String[] args) {
26 | Plot3DCanvas p3d = new Plot3DCanvas(new double[] { 0, 0, 0 }, new double[] { 10, 10, 10 }, new String[] { "lin", "lin", "lin" }, new String[] { "x",
27 | "y", "z" });
28 | new FrameView(p3d);
29 | // p3d.addPlot(DoubleArray.random(10, 3), "plot", "SCATTER");
30 | p3d.addPlotable(new BaseLabel("label", Color.RED, new double[] { -0.1, 0.5, 0.5 }));
31 | }
32 |
33 | public void plot(AbstractDrawer draw) {
34 | draw.setColor(color);
35 | draw.setFont(font);
36 | draw.setTextAngle(angle);
37 | draw.setTextOffset(cornerE, cornerN);
38 | draw.drawTextBase(label, coord);
39 | }
40 |
41 | }
--------------------------------------------------------------------------------
/src/main/java/org/math/plot/plotObjects/BaseLine.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Created on 1 juin 2005 by richet
3 | */
4 | package org.math.plot.plotObjects;
5 |
6 | import java.awt.*;
7 |
8 | import org.math.plot.render.*;
9 |
10 | public class BaseLine extends Line {
11 |
12 | public BaseLine(Color col, double[] c1, double[] c2) {
13 | super(col, c1, c2);
14 | }
15 |
16 | public void plot(AbstractDrawer draw) {
17 | if (!visible)
18 | return;
19 |
20 | draw.setColor(color);
21 | draw.drawLineBase(extrem[0], extrem[1]);
22 | }
23 |
24 | }
25 |
--------------------------------------------------------------------------------
/src/main/java/org/math/plot/plotObjects/BasePlot.java:
--------------------------------------------------------------------------------
1 | package org.math.plot.plotObjects;
2 |
3 | /**
4 | * BSD License
5 | *
6 | * @author Yann RICHET
7 | */
8 |
9 | import java.awt.*;
10 |
11 | import org.math.plot.render.*;
12 |
13 | public class BasePlot implements /*Plotable,*/BaseDependant {
14 |
15 | public static Color DEFAULT_COLOR = Color.DARK_GRAY;
16 |
17 | protected Base base;
18 |
19 | protected Axis[] axis;
20 |
21 | protected boolean visible = true;
22 |
23 | protected Color color;
24 |
25 | public BasePlot(Base b, String... as) {
26 | this(b, DEFAULT_COLOR, as);
27 | }
28 |
29 | public BasePlot(Base b, Color c, Axis... a) {
30 | base = b;
31 | axis = a;
32 | color = c;
33 | }
34 |
35 | public BasePlot(Base b, Color c, String... as) {
36 | base = b;
37 | if (as.length != base.dimension) {
38 | throw new IllegalArgumentException("String array of axes names must have " + base.dimension + " elements.");
39 | }
40 | color = c;
41 | axis = new Axis[base.dimension];
42 | for (int i = 0; i < base.dimension; i++) {
43 | axis[i] = new Axis(base, as[i], color, i);
44 | }
45 | // resetBase();
46 | }
47 |
48 | public void setVisible(boolean v) {
49 | visible = v;
50 | }
51 |
52 | public void setVisible(int i, boolean v) {
53 | axis[i].setVisible(v);
54 | }
55 |
56 | public void setGridVisible(int i, boolean v) {
57 | axis[i].setGridVisible(v);
58 | }
59 |
60 | public boolean getVisible() {
61 | return visible;
62 | }
63 |
64 | public void setColor(Color c) {
65 | color = c;
66 | for (int i = 0; i < axis.length; i++) {
67 | axis[i].setColor(c);
68 | }
69 | }
70 |
71 | public Color getColor() {
72 | return color;
73 | }
74 |
75 | public void setLegend(String[] as) {
76 | if (as.length != base.dimension) {
77 | throw new IllegalArgumentException("String array of axes names must have " + base.dimension + " elements.");
78 | }
79 | for (int i = 0; i < axis.length; i++) {
80 | axis[i].setLegend(as[i]);
81 | }
82 | // resetBase();
83 | }
84 |
85 | public void setLegend(int i, String as) {
86 | axis[i].setLegend(as);
87 | // resetBase();
88 | }
89 |
90 | public String[] getLegend() {
91 | String[] array = new String[axis.length];
92 | for (int i = 0; i < array.length; i++) {
93 | array[i] = axis[i].getLegend();
94 | }
95 | return array;
96 | }
97 |
98 | public String getLegend(int i) {
99 | return axis[i].getLegend();
100 | }
101 |
102 | public void setBase(Base b) {
103 | base = b;
104 | for (int i = 0; i < axis.length; i++) {
105 | axis[i].base = base;
106 | }
107 | resetBase();
108 | }
109 |
110 | public void plot(AbstractDrawer draw) {
111 | if (!visible)
112 | return;
113 |
114 | for (int i = 0; i < axis.length; i++)
115 | axis[i].plot(draw);
116 | }
117 |
118 | public Axis getAxis(int i) {
119 | return axis[i];
120 | }
121 |
122 | public Axis[] getAxis() {
123 | return axis;
124 | }
125 |
126 | public void resetBase() {
127 | // System.out.println("BasePlot.resetBase");
128 | for (int i = 0; i < axis.length; i++) {
129 | axis[i].resetBase();
130 | //base.setAxesScales(i, Base.LINEAR);
131 | }
132 | }
133 |
134 | }
--------------------------------------------------------------------------------
/src/main/java/org/math/plot/plotObjects/Editable.java:
--------------------------------------------------------------------------------
1 | package org.math.plot.plotObjects;
2 |
3 | import org.math.plot.render.*;
4 |
5 | /**
6 | * BSD License
7 | *
8 | * @author Yann RICHET
9 | */
10 | public interface Editable {
11 | public double[] isSelected(int[] screenCoord, AbstractDrawer draw);
12 |
13 | public void edit(Object editParent);
14 |
15 | public void editnote(AbstractDrawer draw);
16 |
17 | }
18 |
--------------------------------------------------------------------------------
/src/main/java/org/math/plot/plotObjects/Label.java:
--------------------------------------------------------------------------------
1 | package org.math.plot.plotObjects;
2 |
3 | import java.awt.*;
4 |
5 | import org.math.plot.render.*;
6 |
7 | /**
8 | * BSD License
9 | *
10 | * @author Yann RICHET
11 | */
12 | public class Label implements Plotable {
13 |
14 | protected double[] coord;
15 |
16 | protected double[] base_offset;
17 |
18 | protected String label;
19 |
20 | protected Color color;
21 |
22 | protected double cornerN = 0.5;
23 |
24 | protected double cornerE = 0.5;
25 |
26 | boolean visible = true;
27 |
28 | public double angle = 0;
29 |
30 | public Font font = AbstractDrawer.DEFAULT_FONT;
31 |
32 | // private static DecimalFormat dec = new DecimalFormat("##0.###E0");
33 |
34 | public Label(String l, Color col, double... c) {
35 | label = l;
36 | coord = c;
37 | color = col;
38 | }
39 |
40 | public Label(String l, double... c) {
41 | this(l, AbstractDrawer.DEFAULT_COLOR, c);
42 | }
43 |
44 | /**
45 | * show coord itself
46 | */
47 | public Label(double... c) {
48 | this(coordToString(c), AbstractDrawer.DEFAULT_COLOR, c);
49 | }
50 |
51 | public void setText(String _t) {
52 | label = _t;
53 | }
54 |
55 | public String getText() {
56 | return label;
57 | }
58 |
59 | public void setCoord(double... _c) {
60 | coord = _c;
61 | }
62 |
63 | public void setColor(Color c) {
64 | color = c;
65 | }
66 |
67 | public Color getColor() {
68 | return color;
69 | }
70 |
71 | /**
72 | * reference point center: 0.5, 0.5 lowerleft: 0,0 upperleft 1, 0 ...
73 | */
74 | public void setCorner(double north_south, double east_west) {
75 | cornerN = north_south;
76 | cornerE = east_west;
77 | }
78 |
79 | public void setVisible(boolean v) {
80 | visible = v;
81 | }
82 |
83 | public boolean getVisible() {
84 | return visible;
85 | }
86 |
87 | /**
88 | * shift by given screen coordinates offset
89 | */
90 | /*
91 | * public void setOffset(double[] offset) { double[] newCoord =
92 | * coord.getPlotCoordCopy(); for (int i = 0; i < newCoord.length; i++) {
93 | * newCoord[i] += offset[i]; } coord.setPlotCoord(newCoord); }
94 | */
95 |
96 | /**
97 | * see Text for formatted text output
98 | */
99 | public void plot(AbstractDrawer draw) {
100 | if (!visible) return;
101 |
102 | draw.setColor(color);
103 | draw.setFont(font);
104 | draw.setBaseOffset(base_offset);
105 | draw.setTextOffset(cornerE, cornerN);
106 | draw.setTextAngle(angle);
107 | draw.drawText(label, coord);
108 | draw.setBaseOffset(null);
109 | }
110 |
111 | public void rotate(double _angle) {
112 | angle = _angle;
113 | }
114 |
115 | public void setFont(Font _font) {
116 | font = _font;
117 | }
118 |
119 | public static double approx(double val, int decimal) {
120 | // double timesEn = val*Math.pow(10,decimal);
121 | // if (Math.rint(timesEn) == timesEn) {
122 | // return val;
123 | // } else {
124 | // to limit precision loss, you need to separate cases where decimal<0
125 | // and >0
126 | // if you don't you'll have this : approx(10000.0,-4) => 10000.00000001
127 | if (decimal < 0) {
128 | return Math.rint(val / Math.pow(10, -decimal)) * Math.pow(10, -decimal);
129 | } else {
130 | return Math.rint(val * Math.pow(10, decimal)) / Math.pow(10, decimal);
131 | }
132 | // }
133 | }
134 |
135 | public static String coordToString(double... c) {
136 | StringBuffer sb = new StringBuffer("(");
137 | for (int i = 0; i < c.length; i++)
138 | sb.append(approx(c[i], 2)).append(",");
139 | // sb.append(dec.format(c.getPlotCoordCopy()[i])).append(",");
140 |
141 | sb.setLength(sb.length() - 1);
142 | if (sb.length() > 0)
143 | sb.append(")");
144 |
145 | return sb.toString();
146 | }
147 |
148 | public Font getFont() {
149 | return font;
150 | }
151 | }
--------------------------------------------------------------------------------
/src/main/java/org/math/plot/plotObjects/Line.java:
--------------------------------------------------------------------------------
1 | package org.math.plot.plotObjects;
2 |
3 | import java.awt.*;
4 |
5 | import org.math.plot.render.*;
6 |
7 | /**
8 | * BSD License
9 | *
10 | * @author Yann RICHET
11 | */
12 | public class Line implements Plotable {
13 |
14 | protected double[][] extrem = new double[2][];
15 |
16 | protected Color color;
17 |
18 | protected Color gradientColor;
19 |
20 | boolean visible = true;
21 |
22 | public Line(Color col, double[] c1, double[] c2) {
23 | extrem[0] = c1;
24 | extrem[1] = c2;
25 | color = col;
26 | }
27 |
28 | public void setColor(Color c) {
29 | color = c;
30 | }
31 |
32 | public Color getColor() {
33 | return color;
34 | }
35 |
36 | public void setVisible(boolean v) {
37 | visible = v;
38 | }
39 |
40 | public boolean getVisible() {
41 | return visible;
42 | }
43 |
44 | public void plot(AbstractDrawer draw) {
45 | if (!visible)
46 | return;
47 |
48 | draw.setColor(color);
49 | if (gradientColor!= null)
50 | draw.setGradient(extrem[0], color, extrem[1], gradientColor);
51 | draw.drawLine(extrem[0], extrem[1]);
52 | if (gradientColor!= null)
53 | draw.resetGradient();
54 | }
55 |
56 | public Color getGradientColor() {
57 | return gradientColor;
58 | }
59 |
60 | public void setGradientColor(Color c) {
61 | this.gradientColor = c;
62 | }
63 | }
--------------------------------------------------------------------------------
/src/main/java/org/math/plot/plotObjects/Noteable.java:
--------------------------------------------------------------------------------
1 | package org.math.plot.plotObjects;
2 |
3 | import org.math.plot.render.*;
4 |
5 | /**
6 | * BSD License
7 | *
8 | * @author Yann RICHET
9 | */
10 | public interface Noteable {
11 | public double[] isSelected(int[] screenCoord, AbstractDrawer draw);
12 |
13 | public void note(AbstractDrawer draw);
14 | }
--------------------------------------------------------------------------------
/src/main/java/org/math/plot/plotObjects/PaintImage.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Created on 5 sept. 2005 by richet
3 | */
4 | package org.math.plot.plotObjects;
5 |
6 | import java.awt.*;
7 |
8 |
9 | import org.math.plot.render.*;
10 |
11 | public class PaintImage implements Plotable {
12 |
13 | public interface Paintable {
14 |
15 | public void paint(Graphics g);
16 | }
17 | protected Paintable source;
18 | protected Image img;
19 | protected double[] xyzSW, xyzSE, xyzNW;
20 | protected boolean visible = true;
21 | protected float alpha;
22 |
23 | public PaintImage(Paintable _source, float _alpha, double[] _xyzSW, double[] _xyzSE, double[] _xyzNW) {
24 | source = _source;
25 |
26 | xyzSW = _xyzSW;
27 | xyzSE = _xyzSE;
28 | xyzNW = _xyzNW;
29 | alpha = _alpha;
30 | }
31 |
32 | public void plot(AbstractDrawer draw) {
33 | if (!visible) {
34 | return;
35 | }
36 |
37 | if (img == null) {
38 | img = draw.canvas.createImage(draw.canvas.getWidth(), draw.canvas.getHeight());
39 | source.paint(img.getGraphics());
40 | }
41 |
42 | draw.drawImage(img, alpha, xyzSW, xyzSE, xyzNW);
43 | }
44 |
45 | public void setVisible(boolean v) {
46 | visible = v;
47 | }
48 |
49 | public boolean getVisible() {
50 | return visible;
51 | }
52 |
53 | public void setColor(Color c) {
54 | throw new IllegalArgumentException("method not available for this Object: PlotImage");
55 | }
56 |
57 | public Color getColor() {
58 | return null;
59 | }
60 | }
61 |
--------------------------------------------------------------------------------
/src/main/java/org/math/plot/plotObjects/Plotable.java:
--------------------------------------------------------------------------------
1 | package org.math.plot.plotObjects;
2 |
3 | import java.awt.*;
4 |
5 | import org.math.plot.render.*;
6 |
7 | /**
8 | * BSD License
9 | *
10 | * @author Yann RICHET
11 | */
12 | public interface Plotable {
13 | public void plot(AbstractDrawer draw);
14 |
15 | public void setVisible(boolean v);
16 |
17 | public boolean getVisible();
18 |
19 | public void setColor(Color c);
20 |
21 | public Color getColor();
22 |
23 | }
--------------------------------------------------------------------------------
/src/main/java/org/math/plot/plotObjects/RasterImage.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Created on 5 sept. 2005 by richet
3 | */
4 | package org.math.plot.plotObjects;
5 |
6 | import java.awt.*;
7 | import java.io.*;
8 |
9 | import javax.swing.*;
10 |
11 | import org.math.plot.*;
12 | import org.math.plot.render.*;
13 |
14 | public class RasterImage implements Plotable{
15 |
16 | File source;
17 | Image img;
18 |
19 | double[] xyzSW, xyzSE,xyzNW;
20 |
21 | boolean visible = true;
22 | float alpha;
23 |
24 | public RasterImage(File _source, float _alpha,double[] _xyzSW, double[] _xyzSE,double[] _xyzNW) {
25 | source = _source;
26 | img = Toolkit.getDefaultToolkit().getImage(source.getPath());
27 | xyzSW = _xyzSW;
28 | xyzSE = _xyzSE;
29 | xyzNW=_xyzNW;
30 | alpha = _alpha;
31 | }
32 |
33 | public void plot(AbstractDrawer draw) {
34 | if (!visible) return;
35 |
36 | draw.drawImage(img,alpha, xyzSW, xyzSE,xyzNW);
37 | }
38 |
39 | public void setVisible(boolean v) {
40 | visible = v;
41 | }
42 |
43 | public boolean getVisible() {
44 | return visible;
45 | }
46 |
47 | public void setColor(Color c) {
48 | throw new IllegalArgumentException("method not available for this Object: PlotImage");
49 | }
50 |
51 | public Color getColor() {
52 | return null;
53 | }
54 |
55 | public static void main(String[] args) {
56 | Plot2DPanel p2 = new Plot2DPanel();
57 | for (int i = 0; i < 1; i++) {
58 | double[][] XYZ = new double[10][2];
59 | for (int j = 0; j < XYZ.length; j++) {
60 | XYZ[j][0] =/*1 + */Math.random();
61 | XYZ[j][1] = /*100 * */Math.random();
62 | }
63 | p2.addScatterPlot("toto" + i, XYZ);
64 | }
65 |
66 | p2.addPlotable(new RasterImage(new File("test.gif"), 0.8f,new double[] {0.2,0.5},new double[] {1.2,0.8},new double[] {0.2,1.1}));
67 |
68 | p2.setLegendOrientation(PlotPanel.SOUTH);
69 | new FrameView(p2).setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
70 |
71 |
72 |
73 | Plot3DPanel p = new Plot3DPanel();
74 | for (int i = 0; i < 1; i++) {
75 | double[][] XYZ = new double[10][3];
76 | for (int j = 0; j < XYZ.length; j++) {
77 | XYZ[j][0] = /*1 +*/ Math.random();
78 | XYZ[j][1] = /*100 **/ Math.random();
79 | XYZ[j][2] = /*0.0001 **/ Math.random();
80 | }
81 | p.addScatterPlot("toto" + i, XYZ);
82 | }
83 |
84 | p.addPlotable(new RasterImage(new File("test.gif"), 0.5f, new double[] {0.0,0.0,0.0},new double[] {1,0,0.0},new double[] {0.0,0,1}));
85 | p.addPlotable(new RasterImage(new File("test.gif"), 0.5f, new double[] {0.0,0.0,0.0},new double[] {0,1,0.0},new double[] {0,0.0,1}));
86 | p.addPlotable(new RasterImage(new File("test.gif"),0.5f, new double[] {0.0,0.0,0.0},new double[] {1,0,0},new double[] {0,1,0}));
87 | // TODO this following case is not totally supported...
88 | //p.addPlotable(new PlotImage(new File("test.jpg"),0.5f, new double[] {1,0,0},new double[] {1,1,0},new double[] {0,0,1}));
89 |
90 |
91 | p.setLegendOrientation(PlotPanel.SOUTH);
92 | p.setPreferredSize(new Dimension(600,600));
93 | new FrameView(p).setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
94 | }
95 |
96 | }
97 |
--------------------------------------------------------------------------------
/src/main/java/org/math/plot/plots/BarPlot.java:
--------------------------------------------------------------------------------
1 | package org.math.plot.plots;
2 |
3 | import java.awt.*;
4 |
5 | import javax.swing.*;
6 |
7 | import org.math.plot.*;
8 | import org.math.plot.render.*;
9 | import org.math.plot.utils.*;
10 |
11 | public class BarPlot extends ScatterPlot {
12 |
13 | public boolean draw_dot = true;
14 |
15 | public BarPlot(String n, Color c, boolean[][] _pattern, double[][] _XY) {
16 | super(n, c, _pattern, _XY);
17 | }
18 |
19 | public BarPlot(String n, Color c, int _type, int _radius, double[][] _XY) {
20 | super(n, c, _type, _radius, _XY);
21 | }
22 |
23 | public BarPlot(String n, Color c, double[][] _XY) {
24 | super(n, c, _XY);
25 | }
26 |
27 | public void plot(AbstractDrawer draw, Color c) {
28 | if (!visible)
29 | return;
30 |
31 | if (draw_dot)
32 | super.plot(draw, c);
33 |
34 | draw.setColor(c);
35 | draw.setLineType(AbstractDrawer.CONTINOUS_LINE);
36 | for (int i = 0; i < XY.length; i++) {
37 | double[] axeprojection = Array.copy(XY[i]);
38 | axeprojection[axeprojection.length - 1] = draw.canvas.base.baseCoords[0][axeprojection.length - 1];
39 | draw.drawLine(XY[i], axeprojection);
40 | }
41 | }
42 |
43 | public static void main(String[] args) {
44 | Plot2DPanel p2 = new Plot2DPanel();
45 | for (int i = 0; i < 3; i++) {
46 | double[][] XYZ = new double[10][2];
47 | for (int j = 0; j < XYZ.length; j++) {
48 | XYZ[j][0] = /*1 + */Math.random();
49 | XYZ[j][1] = /*100 * */Math.random();
50 | }
51 | p2.addBarPlot("toto" + i, XYZ);
52 | }
53 |
54 | p2.setLegendOrientation(PlotPanel.SOUTH);
55 | new FrameView(p2).setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
56 |
57 | Plot3DPanel p = new Plot3DPanel();
58 | for (int i = 0; i < 3; i++) {
59 | double[][] XYZ = new double[10][3];
60 | for (int j = 0; j < XYZ.length; j++) {
61 | XYZ[j][0] = /*1 +*/Math.random();
62 | XYZ[j][1] = /*100 **/Math.random();
63 | XYZ[j][2] = /*0.0001 **/Math.random();
64 | }
65 | p.addBarPlot("toto" + i, XYZ);
66 | }
67 |
68 | p.setLegendOrientation(PlotPanel.SOUTH);
69 | new FrameView(p).setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
70 | }
71 | }
--------------------------------------------------------------------------------
/src/main/java/org/math/plot/plots/BoxPlot2D.java:
--------------------------------------------------------------------------------
1 | package org.math.plot.plots;
2 |
3 | import java.awt.*;
4 |
5 | import org.math.plot.render.*;
6 | import org.math.plot.utils.Array;
7 |
8 | public class BoxPlot2D extends Plot {
9 |
10 | double[] Xmin;
11 | double[] Xmax;
12 | double[] Ymin;
13 | double[] Ymax;
14 | double[][] widths;
15 | double[][] XY;
16 |
17 | public BoxPlot2D(double[][] _XY, double[][] w, Color c, String n) {
18 | super(n, c);
19 | XY = _XY;
20 | widths = w;
21 |
22 | // double[] datasMin = Array.min(XY);
23 | // double[] datasMax = Array.max(XY);
24 | // double[] widthsMax = Array.max(widths);
25 | // double[] min = { datasMin[0] - widthsMax[0] / 2, datasMin[1] -
26 | // widthsMax[1] / 2 };
27 | // double[] max = { datasMax[0] + widthsMax[0] / 2, datasMax[1] +
28 | // widthsMax[1] / 2 };
29 | // base.includeInBounds(min);
30 | // base.includeInBounds(max);
31 |
32 | Xmin = new double[XY.length];
33 | Xmax = new double[XY.length];
34 | Ymin = new double[XY.length];
35 | Ymax = new double[XY.length];
36 | for (int i = 0; i < XY.length; i++) {
37 | Xmin[i] = XY[i][0] - widths[i][0] / 2;
38 | Xmax[i] = XY[i][0] + widths[i][0] / 2;
39 | Ymin[i] = XY[i][1] - widths[i][1] / 2;
40 | Ymax[i] = XY[i][1] + widths[i][1] / 2;
41 | }
42 |
43 | }
44 |
45 | public void plot(AbstractDrawer draw, Color c) {
46 | if (!visible) {
47 | return;
48 | }
49 |
50 | draw.setColor(c);
51 | draw.setLineType(AbstractDrawer.CONTINOUS_LINE);
52 | for (int i = 0; i < XY.length; i++) {
53 | draw.drawLine(new double[]{Xmin[i], Ymin[i]}, new double[]{Xmax[i], Ymin[i]});
54 | draw.drawLine(new double[]{Xmax[i], Ymin[i]}, new double[]{Xmax[i], Ymax[i]});
55 | draw.drawLine(new double[]{Xmax[i], Ymax[i]}, new double[]{Xmin[i], Ymax[i]});
56 | draw.drawLine(new double[]{Xmin[i], Ymax[i]}, new double[]{Xmin[i], Ymin[i]});
57 | draw.setDotType(AbstractDrawer.ROUND_DOT);
58 | draw.setDotRadius(AbstractDrawer.DEFAULT_DOT_RADIUS);
59 | draw.drawDot(XY[i]);
60 | }
61 | }
62 |
63 | @Override
64 | public void setData(double[][] d) {
65 | datapanel = null;
66 | XY = d;
67 | }
68 |
69 | @Override
70 | public double[][] getData() {
71 | return XY;
72 | }
73 |
74 | @Override
75 | public double[][] getBounds() {
76 | return new double[][]{{Array.min(Xmin), Array.min(Ymin)}, {Array.max(Xmax), Array.max(Ymax)}};
77 | }
78 |
79 | public void setDataWidth(double[][] w) {
80 | widths = w;
81 | }
82 |
83 | public double[][] getDataWidth() {
84 | return widths;
85 | }
86 |
87 | public void setData(double[][] d, double[][] w) {
88 | setData(d);
89 | widths = w;
90 | }
91 |
92 | public double[] isSelected(int[] screenCoordTest, AbstractDrawer draw) {
93 | for (int i = 0; i < XY.length; i++) {
94 | int[] screenCoord = draw.project(XY[i]);
95 |
96 | if ((screenCoord[0] + note_precision > screenCoordTest[0]) && (screenCoord[0] - note_precision < screenCoordTest[0])
97 | && (screenCoord[1] + note_precision > screenCoordTest[1]) && (screenCoord[1] - note_precision < screenCoordTest[1])) {
98 | return XY[i];
99 | }
100 | }
101 | return null;
102 | }
103 | }
--------------------------------------------------------------------------------
/src/main/java/org/math/plot/plots/BoxPlot3D.java:
--------------------------------------------------------------------------------
1 | package org.math.plot.plots;
2 |
3 | import java.awt.*;
4 |
5 | import javax.swing.JFrame;
6 | import org.math.plot.FrameView;
7 | import org.math.plot.Plot3DPanel;
8 | import org.math.plot.PlotPanel;
9 | import org.math.plot.render.*;
10 | import org.math.plot.utils.Array;
11 |
12 | public class BoxPlot3D extends Plot {
13 |
14 | double[] Xmin;
15 | double[] Xmax;
16 | double[] Ymin;
17 | double[] Ymax;
18 | double[] Zmin;
19 | double[] Zmax;
20 | double[][] widths;
21 | double[][] XY;
22 |
23 | public BoxPlot3D(double[][] _XY, double[][] w, Color c, String n) {
24 | super(n, c);
25 | XY = _XY;
26 | widths = w;
27 |
28 | // double[] datasMin = Array.min(XY);
29 | // double[] datasMax = Array.max(XY);
30 | // double[] widthsMax = Array.max(widths);
31 | // double[] min = { datasMin[0] - widthsMax[0] / 2, datasMin[1] -
32 | // widthsMax[1] / 2, datasMin[2] - widthsMax[2] / 2 };
33 | // double[] max = { datasMax[0] + widthsMax[0] / 2, datasMax[1] +
34 | // widthsMax[1] / 2, datasMax[2] + widthsMax[2] / 2 };
35 | // base.includeInBounds(min);
36 | // base.includeInBounds(max);
37 |
38 | Xmin = new double[XY.length];
39 | Xmax = new double[XY.length];
40 | Ymin = new double[XY.length];
41 | Ymax = new double[XY.length];
42 | Zmin = new double[XY.length];
43 | Zmax = new double[XY.length];
44 | for (int i = 0; i < XY.length; i++) {
45 | Xmin[i] = XY[i][0] - widths[i][0] / 2;
46 | Xmax[i] = XY[i][0] + widths[i][0] / 2;
47 | Ymin[i] = XY[i][1] - widths[i][1] / 2;
48 | Ymax[i] = XY[i][1] + widths[i][1] / 2;
49 | Zmin[i] = XY[i][2] - widths[i][2] / 2;
50 | Zmax[i] = XY[i][2] + widths[i][2] / 2;
51 | }
52 | }
53 |
54 | public void plot(AbstractDrawer draw, Color c) {
55 | if (!visible) {
56 | return;
57 | }
58 |
59 | draw.setColor(c);
60 | draw.setLineType(AbstractDrawer.CONTINOUS_LINE);
61 | for (int i = 0; i < XY.length; i++) {
62 | draw.drawLine(new double[]{Xmin[i], Ymin[i], Zmin[i]}, new double[]{Xmax[i], Ymin[i], Zmin[i]});
63 | draw.drawLine(new double[]{Xmax[i], Ymin[i], Zmin[i]}, new double[]{Xmax[i], Ymax[i], Zmin[i]});
64 | draw.drawLine(new double[]{Xmax[i], Ymax[i], Zmin[i]}, new double[]{Xmin[i], Ymax[i], Zmin[i]});
65 | draw.drawLine(new double[]{Xmin[i], Ymax[i], Zmin[i]}, new double[]{Xmin[i], Ymin[i], Zmin[i]});
66 |
67 | draw.drawLine(new double[]{Xmin[i], Ymin[i], Zmax[i]}, new double[]{Xmax[i], Ymin[i], Zmax[i]});
68 | draw.drawLine(new double[]{Xmax[i], Ymin[i], Zmax[i]}, new double[]{Xmax[i], Ymax[i], Zmax[i]});
69 | draw.drawLine(new double[]{Xmax[i], Ymax[i], Zmax[i]}, new double[]{Xmin[i], Ymax[i], Zmax[i]});
70 | draw.drawLine(new double[]{Xmin[i], Ymax[i], Zmax[i]}, new double[]{Xmin[i], Ymin[i], Zmax[i]});
71 |
72 | draw.drawLine(new double[]{Xmin[i], Ymin[i], Zmin[i]}, new double[]{Xmin[i], Ymin[i], Zmax[i]});
73 | draw.drawLine(new double[]{Xmax[i], Ymin[i], Zmin[i]}, new double[]{Xmax[i], Ymin[i], Zmax[i]});
74 | draw.drawLine(new double[]{Xmin[i], Ymax[i], Zmin[i]}, new double[]{Xmin[i], Ymax[i], Zmax[i]});
75 | draw.drawLine(new double[]{Xmax[i], Ymax[i], Zmin[i]}, new double[]{Xmax[i], Ymax[i], Zmax[i]});
76 |
77 | draw.drawDot(XY[i]);
78 | }
79 | }
80 |
81 | @Override
82 | public void setData(double[][] d) {
83 | datapanel = null;
84 | XY = d;
85 | }
86 |
87 | @Override
88 | public double[][] getData() {
89 | return XY;
90 | }
91 |
92 | @Override
93 | public double[][] getBounds() {
94 | return new double[][]{{Array.min(Xmin), Array.min(Ymin), Array.min(Zmin)}, {Array.max(Xmax), Array.max(Ymax), Array.max(Zmax)}};
95 | }
96 |
97 | public void setDataWidth(double[][] w) {
98 | widths = w;
99 | }
100 |
101 | public double[][] getDataWidth() {
102 | return widths;
103 | }
104 |
105 | public void setData(double[][] d, double[][] w) {
106 | setData(d);
107 | widths = w;
108 | }
109 |
110 | public double[] isSelected(int[] screenCoordTest, AbstractDrawer draw) {
111 | for (int i = 0; i < XY.length; i++) {
112 | int[] screenCoord = draw.project(XY[i]);
113 |
114 | if ((screenCoord[0] + note_precision > screenCoordTest[0]) && (screenCoord[0] - note_precision < screenCoordTest[0])
115 | && (screenCoord[1] + note_precision > screenCoordTest[1]) && (screenCoord[1] - note_precision < screenCoordTest[1])) {
116 | return XY[i];
117 | }
118 | }
119 | return null;
120 | }
121 |
122 | public static void main(String[] args) {
123 | Plot3DPanel plotpanel = new Plot3DPanel();
124 | for (int i = 0; i < 1; i++) {
125 | double[][] receiverXYZ = new double[100][6];
126 | for (int j = 0; j < receiverXYZ.length; j++) {
127 | receiverXYZ[j][0] = /*1 + */ Math.random();
128 | receiverXYZ[j][1] = /*100 * */ Math.random();
129 | receiverXYZ[j][2] = /*100 * */ Math.random();
130 | receiverXYZ[j][3] = /*1 + */ Math.random() / 10;
131 | receiverXYZ[j][4] = /*100 * */ Math.random() / 10;
132 | receiverXYZ[j][5] = /*100 * */ Math.random() / 10;
133 | }
134 | int receiverPlotDataIndex = plotpanel.addBoxPlot("Receivers", Color.orange, receiverXYZ);
135 | }
136 |
137 | plotpanel.setLegendOrientation(PlotPanel.SOUTH);
138 | new FrameView(plotpanel).setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
139 | }
140 | }
--------------------------------------------------------------------------------
/src/main/java/org/math/plot/plots/CloudPlot2D.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Created on 13 juil. 07 by richet
3 | */
4 | package org.math.plot.plots;
5 |
6 | import java.awt.Color;
7 |
8 | import javax.swing.JFrame;
9 |
10 | import org.math.plot.FrameView;
11 | import org.math.plot.Plot2DPanel;
12 | import org.math.plot.PlotPanel;
13 | import org.math.plot.render.AbstractDrawer;
14 | import org.math.plot.utils.Array;
15 |
16 | public class CloudPlot2D extends Plot {
17 |
18 | double[][] NW;
19 | double[][] NE;
20 | double[][] SW;
21 | double[][] SE;
22 | double[] width_constant = {-1, -1};
23 | double[][] XY;
24 | float[] f;
25 | boolean fill_shape = true;
26 |
27 | public CloudPlot2D(String n, Color c, double[][] _XYcard, double wX, double wY) {
28 | super(n, c);
29 | splitXYf(_XYcard);
30 | width_constant = new double[]{wX, wY};
31 |
32 | build();
33 | }
34 |
35 | private void splitXYf(double[][] xycard) {
36 | XY = new double[xycard.length][2];
37 | f = new float[xycard.length];
38 | float normf = 0;
39 | for (int i = 0; i < xycard.length; i++) {
40 | XY[i][0] = xycard[i][0];
41 | XY[i][1] = xycard[i][1];
42 | f[i] = (float) xycard[i][2];
43 | normf += f[i];//Math.max(normf, f[i]);
44 | }
45 |
46 | for (int i = 0; i < f.length; i++) {
47 | f[i] = f[i] / normf;
48 | }
49 |
50 | }
51 |
52 | private void build() {
53 | if (width_constant[0] > 0) {
54 | NW = new double[XY.length][];
55 | NE = new double[XY.length][];
56 | SW = new double[XY.length][];
57 | SE = new double[XY.length][];
58 | for (int i = 0; i < XY.length; i++) {
59 | NW[i] = new double[]{XY[i][0] - width_constant[0] / 2, XY[i][1] + width_constant[1] / 2};
60 | NE[i] = new double[]{XY[i][0] + width_constant[0] / 2, XY[i][1] + width_constant[1] / 2};
61 | SW[i] = new double[]{XY[i][0] - width_constant[0] / 2, XY[i][1] - width_constant[1] / 2};
62 | SE[i] = new double[]{XY[i][0] + width_constant[0] / 2, XY[i][1] - width_constant[1] / 2};
63 | }
64 | }
65 | }
66 |
67 | public void plot(AbstractDrawer draw, Color c) {
68 | if (!visible) {
69 | return;
70 | }
71 |
72 | draw.canvas.includeInBounds(SW[0]);
73 | draw.canvas.includeInBounds(NE[XY.length - 1]);
74 |
75 | draw.setColor(c);
76 | draw.setLineType(AbstractDrawer.CONTINOUS_LINE);
77 | for (int i = 0; i < XY.length; i++) {
78 | if (f[i] > 0) {
79 | draw.fillPolygon(f[i], NW[i], NE[i], SE[i], SW[i]);
80 | }
81 | }
82 | }
83 |
84 | @Override
85 | public void setData(double[][] d) {
86 | datapanel = null;
87 | splitXYf(d);
88 | }
89 |
90 | @Override
91 | public double[][] getData() {
92 | return XY;
93 | }
94 |
95 | @Override
96 | public double[][] getBounds() {
97 | double[][] b = new double[][]{Array.min(XY), Array.max(XY)};
98 | for (int i = 0; i < b[0].length; i++) {
99 | b[0][i] = b[0][i] - width_constant[i] / 2;
100 | b[1][i] = b[1][i] + width_constant[i] / 2;
101 | }
102 | return b;
103 | }
104 |
105 | public double[] isSelected(int[] screenCoordTest, AbstractDrawer draw) {
106 | for (int i = 0; i < XY.length; i++) {
107 | int[] screenCoord = draw.project(XY[i]);
108 |
109 | if ((screenCoord[0] + note_precision > screenCoordTest[0]) && (screenCoord[0] - note_precision < screenCoordTest[0])
110 | && (screenCoord[1] + note_precision > screenCoordTest[1]) && (screenCoord[1] - note_precision < screenCoordTest[1])) {
111 | return XY[i];
112 | }
113 | }
114 | return null;
115 | }
116 |
117 | public static void main(String[] args) {
118 | Plot2DPanel p = new Plot2DPanel();
119 |
120 | double[][] cloud = new double[100][2];
121 | for (int i = 0; i < cloud.length; i++) {
122 | cloud[i][0] = Math.random() + Math.random();
123 | cloud[i][1] = Math.random() + Math.random();
124 | }
125 | p.addCloudPlot("cloud", Color.RED, cloud, 5, 5);
126 |
127 | double[][] cloud2 = new double[100][2];
128 | for (int i = 0; i < cloud2.length; i++) {
129 | cloud2[i][0] = 2 + Math.random() + Math.random();
130 | cloud2[i][1] = 2 + Math.random() + Math.random();
131 | }
132 | p.addCloudPlot("cloud2", Color.RED, cloud2, 5, 5);
133 |
134 | p.setLegendOrientation(PlotPanel.SOUTH);
135 | new FrameView(p).setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
136 | }
137 | }
138 |
--------------------------------------------------------------------------------
/src/main/java/org/math/plot/plots/CloudPlot3D.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Created on 13 juil. 07 by richet
3 | */
4 | package org.math.plot.plots;
5 |
6 | import java.awt.Color;
7 |
8 | import javax.swing.JFrame;
9 |
10 | import org.math.plot.FrameView;
11 | import org.math.plot.Plot3DPanel;
12 | import org.math.plot.PlotPanel;
13 | import org.math.plot.render.AbstractDrawer;
14 | import org.math.plot.utils.Array;
15 |
16 | public class CloudPlot3D extends Plot {
17 |
18 | double[][] topNW;
19 | double[][] topNE;
20 | double[][] topSW;
21 | double[][] topSE;
22 | double[][] botNW;
23 | double[][] botNE;
24 | double[][] botSW;
25 | double[][] botSE;
26 | double[] width_constant = {-1, -1, -1};
27 | double[][] XY;
28 | float[] f;
29 | boolean fill_shape = true;
30 |
31 | public CloudPlot3D(String n, Color c, double[][] _XYcard, double wX, double wY, double wZ) {
32 | super(n, c);
33 | splitXYf(_XYcard);
34 | width_constant = new double[]{wX, wY, wZ};
35 |
36 | build();
37 | }
38 |
39 | private void splitXYf(double[][] xycard) {
40 | XY = new double[xycard.length][3];
41 | f = new float[xycard.length];
42 | float normf = 0;
43 | for (int i = 0; i < xycard.length; i++) {
44 | XY[i][0] = xycard[i][0];
45 | XY[i][1] = xycard[i][1];
46 | XY[i][2] = xycard[i][2];
47 | f[i] = (float) xycard[i][3];
48 | normf += f[i];//Math.max(normf, f[i]);
49 | }
50 |
51 | for (int i = 0; i < f.length; i++) {
52 | f[i] = f[i] / normf;
53 | }
54 |
55 | }
56 |
57 | private void build() {
58 | if (width_constant[0] > 0) {
59 | topNW = new double[XY.length][];
60 | topNE = new double[XY.length][];
61 | topSW = new double[XY.length][];
62 | topSE = new double[XY.length][];
63 | botNW = new double[XY.length][];
64 | botNE = new double[XY.length][];
65 | botSW = new double[XY.length][];
66 | botSE = new double[XY.length][];
67 | for (int i = 0; i < XY.length; i++) {
68 | topNW[i] = new double[]{XY[i][0] - width_constant[0] / 2, XY[i][1] + width_constant[1] / 2, XY[i][2] + width_constant[2] / 2};
69 | topNE[i] = new double[]{XY[i][0] + width_constant[0] / 2, XY[i][1] + width_constant[1] / 2, XY[i][2] + width_constant[2] / 2};
70 | topSW[i] = new double[]{XY[i][0] - width_constant[0] / 2, XY[i][1] - width_constant[1] / 2, XY[i][2] + width_constant[2] / 2};
71 | topSE[i] = new double[]{XY[i][0] + width_constant[0] / 2, XY[i][1] - width_constant[1] / 2, XY[i][2] + width_constant[2] / 2};
72 | botNW[i] = new double[]{XY[i][0] - width_constant[0] / 2, XY[i][1] + width_constant[1] / 2, XY[i][2] - width_constant[2] / 2};
73 | botNE[i] = new double[]{XY[i][0] + width_constant[0] / 2, XY[i][1] + width_constant[1] / 2, XY[i][2] - width_constant[2] / 2};
74 | botSW[i] = new double[]{XY[i][0] - width_constant[0] / 2, XY[i][1] - width_constant[1] / 2, XY[i][2] - width_constant[2] / 2};
75 | botSE[i] = new double[]{XY[i][0] + width_constant[0] / 2, XY[i][1] - width_constant[1] / 2, XY[i][2] - width_constant[2] / 2};
76 | }
77 | }
78 | }
79 |
80 | public void plot(AbstractDrawer draw, Color c) {
81 | if (!visible) {
82 | return;
83 | }
84 |
85 | draw.canvas.includeInBounds(botSW[0]);
86 | draw.canvas.includeInBounds(topNE[XY.length - 1]);
87 |
88 | draw.setColor(c);
89 | draw.setLineType(AbstractDrawer.CONTINOUS_LINE);
90 | for (int i = 0; i < XY.length; i++) {
91 | if (f[i] > 0) {
92 | draw.fillPolygon(f[i], topNW[i], topNE[i], topSE[i], topSW[i]);
93 | draw.fillPolygon(f[i], botNW[i], botNE[i], botSE[i], botSW[i]);
94 |
95 | draw.fillPolygon(f[i], botNW[i], botNE[i], topNE[i], topNW[i]);
96 | draw.fillPolygon(f[i], botSW[i], botSE[i], topSE[i], topSW[i]);
97 |
98 | draw.fillPolygon(f[i], botNW[i], botSW[i], topSW[i], topNW[i]);
99 | draw.fillPolygon(f[i], botNE[i], botSE[i], topSE[i], topNE[i]);
100 | }
101 | }
102 | }
103 |
104 | @Override
105 | public void setData(double[][] d) {
106 | datapanel = null;
107 | splitXYf(d);
108 | }
109 |
110 | @Override
111 | public double[][] getData() {
112 | return XY;
113 | }
114 |
115 | @Override
116 | public double[][] getBounds() {
117 | double[][] b = new double[][]{Array.min(XY), Array.max(XY)};
118 | for (int i = 0; i < b[0].length; i++) {
119 | b[0][i] = b[0][i] - width_constant[i] / 2;
120 | b[1][i] = b[1][i] + width_constant[i] / 2;
121 | }
122 | return b;
123 | }
124 |
125 | public double[] isSelected(int[] screenCoordTest, AbstractDrawer draw) {
126 | for (int i = 0; i < XY.length; i++) {
127 | int[] screenCoord = draw.project(XY[i]);
128 |
129 | if ((screenCoord[0] + note_precision > screenCoordTest[0]) && (screenCoord[0] - note_precision < screenCoordTest[0])
130 | && (screenCoord[1] + note_precision > screenCoordTest[1]) && (screenCoord[1] - note_precision < screenCoordTest[1])) {
131 | return XY[i];
132 | }
133 | }
134 | return null;
135 | }
136 |
137 | public static void main(String[] args) {
138 | Plot3DPanel p = new Plot3DPanel();
139 |
140 | //triangular random cloud (as sum of two uniform random numbers)
141 | double[][] cloud = new double[100][3];
142 | for (int i = 0; i < cloud.length; i++) {
143 | cloud[i][0] = Math.random() + Math.random();
144 | cloud[i][1] = Math.random() + Math.random();
145 | cloud[i][2] = Math.random() + Math.random();
146 | }
147 | p.addCloudPlot("cloud", Color.RED, cloud, 3, 3, 3);
148 |
149 | double[][] cloud2 = new double[100][3];
150 | for (int i = 0; i < cloud.length; i++) {
151 | cloud2[i][0] = 2 + Math.random() + Math.random();
152 | cloud2[i][1] = 2 + Math.random() + Math.random();
153 | cloud2[i][2] = 2 + Math.random() + Math.random();
154 | }
155 | p.addCloudPlot("cloud2", Color.RED, cloud2, 3, 3, 3);
156 |
157 | p.setLegendOrientation(PlotPanel.SOUTH);
158 | new FrameView(p).setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
159 | }
160 | }
161 |
--------------------------------------------------------------------------------
/src/main/java/org/math/plot/plots/DensityLayerPlot.java:
--------------------------------------------------------------------------------
1 | package org.math.plot.plots;
2 |
3 | import java.awt.Color;
4 |
5 | import javax.swing.JFrame;
6 |
7 | import org.math.plot.FrameView;
8 | import org.math.plot.Plot2DPanel;
9 | import org.math.plot.render.AbstractDrawer;
10 | import org.math.plot.utils.Array;
11 |
12 | /**
13 | * @author Yann RICHET
14 | */
15 |
16 | public class DensityLayerPlot extends LayerPlot {
17 |
18 | public static int WIDTH = 2;
19 |
20 | int axis;
21 |
22 | double[] constant_Q;
23 |
24 | double[][] Q;
25 |
26 | public DensityLayerPlot(Plot p, int a, double[] quantiles) {
27 | this(p, a, new double[0][0]);
28 | constant_Q = quantiles;
29 | }
30 |
31 | /** Build a quantile plot based on given plot. The quantile is drawn as a linear gradient from the base plot dots.
32 | * @param p base plot
33 | * @param a axis number of quantile : 0=X quantile, 1=Y quantile, 2=Z quantile
34 | * @param quantiles array of standard deviation values
35 | */
36 | public DensityLayerPlot(Plot p, int a, double[][] quantiles) {
37 | super("Density of " + p.name, p);
38 | if (quantiles != null && quantiles.length > 0)
39 | Array.checkRowDimension(quantiles, p.getData().length);
40 | Q = quantiles;
41 | axis = a;
42 | }
43 |
44 | public int getAxe() {
45 | return axis;
46 | }
47 |
48 | public void plot(AbstractDrawer draw, Color c) {
49 | if (!plot.visible)
50 | return;
51 |
52 | draw.setColor(c);
53 |
54 | draw.setLineType(AbstractDrawer.CONTINOUS_LINE);
55 | draw.setLineWidth(WIDTH);
56 | if (constant_Q == null)
57 | for (int i = 0; i < plot.getData().length; i++) {
58 |
59 | double norm = Double.MAX_VALUE;
60 | for (int j = 0; j < Q[i].length - 1; j++)
61 | norm = Math.min(1 / (Q[i][j + 1] - Q[i][j]), norm);
62 |
63 | double[] d0 = Array.getRowCopy(plot.getData(), i);
64 | double[] d1 = Array.getRowCopy(plot.getData(), i);
65 | double[] d2 = Array.getRowCopy(plot.getData(), i);
66 |
67 | for (int j = 0; j < Q[i].length - 2; j++) {
68 | d1[axis] = d0[axis] + ((Q[i][j] + Q[i][j + 1]) / 2);
69 | d2[axis] = d0[axis] + ((Q[i][j + 1] + Q[i][j + 2]) / 2);
70 | Color c1 = new Color(c.getRed(), c.getGreen(), c.getBlue(), (int) (255.0 * (norm / (Q[i][j + 1] - Q[i][j]))));
71 | Color c2 = new Color(c.getRed(), c.getGreen(), c.getBlue(), (int) (255.0 * (norm / (Q[i][j + 2] - Q[i][j + 1]))));
72 | draw.setGradient(d1, c1, d2, c2);
73 | draw.drawLine(d1, d2);
74 | }
75 | }
76 | else {
77 |
78 | double norm = Double.MAX_VALUE;
79 | for (int j = 0; j < constant_Q.length - 1; j++)
80 | norm = Math.min(1 / (constant_Q[j + 1] - constant_Q[j]), norm);
81 |
82 | for (int i = 0; i < plot.getData().length; i++) {
83 | double[] d0 = Array.getRowCopy(plot.getData(), i);
84 | double[] d1 = Array.getRowCopy(plot.getData(), i);
85 | double[] d2 = Array.getRowCopy(plot.getData(), i);
86 |
87 | for (int j = 0; j < constant_Q.length - 2; j++) {
88 | d1[axis] = d0[axis] + (constant_Q[j] + constant_Q[j + 1]) / 2;
89 | d2[axis] = d0[axis] + (constant_Q[j + 1] + constant_Q[j + 2]) / 2;
90 | Color c1 = new Color(c.getRed(), c.getGreen(), c.getBlue(), (int) (255.0 * (norm / (constant_Q[j + 1] - constant_Q[j]))));
91 | Color c2 = new Color(c.getRed(), c.getGreen(), c.getBlue(), (int) (255.0 * (norm / (constant_Q[j + 2] - constant_Q[j + 1]))));
92 | draw.setGradient(d1, c1, d2, c2);
93 | draw.drawLine(d1, d2);
94 | }
95 | }
96 | }
97 | draw.resetGradient();
98 | draw.setLineWidth(AbstractDrawer.DEFAULT_LINE_WIDTH);
99 |
100 | }
101 |
102 | @Override
103 | public void setData(double[][] d) {
104 | //Q = d[0];
105 | }
106 |
107 | @Override
108 | public double[][] getData() {
109 | return null;//new double[][] { sigma };
110 | }
111 |
112 | public static void main(String[] args) {
113 | Plot2DPanel p2 = new Plot2DPanel();
114 | for (int i = 0; i < 2; i++) {
115 | double[][] XYZ = new double[10][2];
116 | for (int j = 0; j < XYZ.length; j++) {
117 | XYZ[j][0] = /*1 + */Math.random();
118 | XYZ[j][1] = /*100 * */10 * Math.random();
119 | }
120 |
121 | p2.addScatterPlot("toto" + i, XYZ);
122 | }
123 | p2.getPlot(0).addQuantiles(1, new double[] {/*-3,-2,*/-4, -2, -0.5, 0, 0.5, 2, 4 /*,2,3*/});
124 | p2.getPlot(1).addQuantiles(1, new double[] { -3, -2, -1, 0, 1, 2, 3 });
125 | //p2.getPlot(1).addLayer(new DensityLayerPlot(p2.getPlot(1), 1, new double[] { -.1, 0, .1 }));
126 |
127 | new FrameView(p2).setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
128 | }
129 | }
--------------------------------------------------------------------------------
/src/main/java/org/math/plot/plots/GaussianDensityLayerPlot.java:
--------------------------------------------------------------------------------
1 | package org.math.plot.plots;
2 |
3 | import java.awt.Color;
4 |
5 | import javax.swing.JFrame;
6 |
7 | import org.math.plot.FrameView;
8 | import org.math.plot.Plot2DPanel;
9 | import org.math.plot.render.AbstractDrawer;
10 | import org.math.plot.utils.Array;
11 |
12 | /**
13 | * @author Yann RICHET
14 | */
15 |
16 | public class GaussianDensityLayerPlot extends LayerPlot {
17 |
18 | public static int WIDHT = 2;
19 |
20 | int axis;
21 |
22 | Color gradC_0sigma, gradC_1sigma, gradC_2sigma, gradC_3sigma;
23 |
24 | double constant_sigma = 0;
25 |
26 | double[] sigma;
27 |
28 | private float[][] gausspdf_sigma;
29 |
30 | public GaussianDensityLayerPlot(Plot p, int ax, double sigma) {
31 | this(p, ax, null);
32 | constant_sigma = sigma;
33 |
34 | gausspdf_sigma = new float[1][4];
35 | for (int i = 0; i < gausspdf_sigma.length; i++)
36 | for (int j = 0; j < 4; j++)
37 | gausspdf_sigma[i][j] = (float) (/*1.0 / Math.sqrt(2 * Math.PI * constant_sigma * constant_sigma) */Math.exp(-(j * j)
38 | / (2.0 * constant_sigma * constant_sigma)));
39 |
40 | }
41 |
42 | /*public QuantilePlot(Plot p, int a, double q) {
43 | this(p, a, q, DEFAULT_RATE,true);
44 | }*/
45 |
46 | /** Build a gauss quantile plot based on given plot. The quantile is drawn as a gaussian gradient from the base plot dots.
47 | * @param p base plot
48 | * @param ax axis number of quantile : 0=X quantile, 1=Y quantile, 2=Z quantile
49 | * @param sigma array of standard deviation values
50 | */
51 | public GaussianDensityLayerPlot(Plot p, int ax, double[] sigma) {
52 | super("Gauss quantile of " + p.name, p);
53 | if (sigma != null)
54 | Array.checkLength(sigma, p.getData().length);
55 | this.sigma = sigma;
56 | axis = ax;
57 |
58 | if (sigma != null) {
59 | gausspdf_sigma = new float[sigma.length][4];
60 | for (int i = 0; i < gausspdf_sigma.length; i++) {
61 | for (int j = 0; j < 4; j++)
62 | gausspdf_sigma[i][j] = (float) (/*1.0 / Math.sqrt(2 * Math.PI * sigma[i] * sigma[i]) */Math.exp(-(j * j) / (2.0 * sigma[i] * sigma[i])));
63 | }
64 | }
65 |
66 | }
67 |
68 | public double getQuantilesValue(int numCoord) {
69 | return sigma[numCoord];
70 | }
71 |
72 | public int getAxe() {
73 | return axis;
74 | }
75 |
76 | public void plot(AbstractDrawer draw, Color c) {
77 | if (!plot.visible)
78 | return;
79 |
80 | draw.setColor(c);
81 |
82 | draw.setLineType(AbstractDrawer.CONTINOUS_LINE);
83 | draw.setLineWidth(WIDHT);
84 | if (constant_sigma == 0)
85 | for (int i = 0; i < plot.getData().length; i++) {
86 | gradC_0sigma = new Color(c.getRed(), c.getGreen(), c.getBlue(), (int) (255.0 * (gausspdf_sigma[i][0])));
87 | gradC_1sigma = new Color(c.getRed(), c.getGreen(), c.getBlue(), (int) (255.0 * (gausspdf_sigma[i][1])));
88 | gradC_2sigma = new Color(c.getRed(), c.getGreen(), c.getBlue(), (int) (255.0 * (gausspdf_sigma[i][2])));
89 | gradC_3sigma = new Color(c.getRed(), c.getGreen(), c.getBlue(), (int) (255.0 * (gausspdf_sigma[i][3])));
90 |
91 | double[] d = Array.getRowCopy(plot.getData(), i);
92 | double[] d2 = Array.getRowCopy(plot.getData(), i);
93 | d2[axis] += sigma[i];
94 | draw.setGradient(d, gradC_0sigma, d2, gradC_1sigma);
95 | draw.drawLine(d, d2);
96 |
97 | d[axis] += sigma[i];
98 | d2[axis] += sigma[i];
99 | draw.setGradient(d, gradC_1sigma, d2, gradC_2sigma);
100 | draw.drawLine(d, d2);
101 |
102 | d[axis] += sigma[i];
103 | d2[axis] += sigma[i];
104 | draw.setGradient(d, gradC_2sigma, d2, gradC_3sigma);
105 | draw.drawLine(d, d2);
106 |
107 | d = Array.getRowCopy(plot.getData(), i);
108 | d2 = Array.getRowCopy(plot.getData(), i);
109 | d2[axis] -= sigma[i];
110 | draw.setGradient(d2, gradC_1sigma, d, gradC_0sigma);
111 | draw.drawLine(d2, d);
112 |
113 | d[axis] -= sigma[i];
114 | d2[axis] -= sigma[i];
115 | draw.setGradient(d2, gradC_2sigma, d, gradC_1sigma);
116 | draw.drawLine(d2, d);
117 |
118 | d[axis] -= sigma[i];
119 | d2[axis] -= sigma[i];
120 | draw.setGradient(d2, gradC_3sigma, d, gradC_2sigma);
121 | draw.drawLine(d2, d);
122 | }
123 | else {
124 | gradC_0sigma = new Color(c.getRed(), c.getGreen(), c.getBlue(), (int) (255.0 * (gausspdf_sigma[0][0])));
125 | gradC_1sigma = new Color(c.getRed(), c.getGreen(), c.getBlue(), (int) (255.0 * (gausspdf_sigma[0][1])));
126 | gradC_2sigma = new Color(c.getRed(), c.getGreen(), c.getBlue(), (int) (255.0 * (gausspdf_sigma[0][2])));
127 | gradC_3sigma = new Color(c.getRed(), c.getGreen(), c.getBlue(), (int) (255.0 * (gausspdf_sigma[0][3])));
128 |
129 | for (int i = 0; i < plot.getData().length; i++) {
130 |
131 | double[] d = Array.getRowCopy(plot.getData(), i);
132 | double[] d2 = Array.getRowCopy(plot.getData(), i);
133 | d2[axis] += constant_sigma;
134 | draw.setGradient(d, gradC_0sigma, d2, gradC_1sigma);
135 | draw.drawLine(d, d2);
136 |
137 | d[axis] += constant_sigma;
138 | d2[axis] += constant_sigma;
139 | draw.setGradient(d, gradC_1sigma, d2, gradC_2sigma);
140 | draw.drawLine(d, d2);
141 |
142 | d[axis] += constant_sigma;
143 | d2[axis] += constant_sigma;
144 | draw.setGradient(d, gradC_2sigma, d2, gradC_3sigma);
145 | draw.drawLine(d, d2);
146 |
147 | d = Array.getRowCopy(plot.getData(), i);
148 | d2 = Array.getRowCopy(plot.getData(), i);
149 | d2[axis] -= constant_sigma;
150 | draw.setGradient(d2, gradC_1sigma, d, gradC_0sigma);
151 | draw.drawLine(d2, d);
152 |
153 | d[axis] -= constant_sigma;
154 | d2[axis] -= constant_sigma;
155 | draw.setGradient(d2, gradC_2sigma, d, gradC_1sigma);
156 | draw.drawLine(d2, d);
157 |
158 | d[axis] -= constant_sigma;
159 | d2[axis] -= constant_sigma;
160 | draw.setGradient(d2, gradC_3sigma, d, gradC_2sigma);
161 | draw.drawLine(d2, d);
162 | }
163 | }
164 | draw.resetGradient();
165 | draw.setLineWidth(AbstractDrawer.DEFAULT_LINE_WIDTH);
166 |
167 | }
168 |
169 | @Override
170 | public void setData(double[][] d) {
171 | sigma = d[0];
172 | }
173 |
174 | @Override
175 | public double[][] getData() {
176 | return new double[][] { sigma };
177 | }
178 |
179 | public static void main(String[] args) {
180 | double[] sXYZ = null;
181 |
182 | Plot2DPanel p2 = new Plot2DPanel();
183 | for (int i = 0; i < 2; i++) {
184 | double[][] XYZ = new double[10][2];
185 | sXYZ = new double[10];
186 | for (int j = 0; j < XYZ.length; j++) {
187 | XYZ[j][0] = /*1 + */Math.random();
188 | XYZ[j][1] = /*100 * */Math.random();
189 | sXYZ[j] = /*100 * */Math.random();
190 | }
191 |
192 | p2.addScatterPlot("toto" + i, XYZ);
193 | }
194 | p2.getPlot(0).addGaussQuantiles(0, sXYZ);
195 | p2.getPlot(1).addGaussQuantiles(1, 0.1);
196 |
197 | new FrameView(p2).setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
198 | }
199 | }
--------------------------------------------------------------------------------
/src/main/java/org/math/plot/plots/GridPlot3D.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Created on 3 juin 2005 by richet
3 | */
4 | package org.math.plot.plots;
5 |
6 | import java.awt.*;
7 |
8 | import org.math.plot.*;
9 | import org.math.plot.render.*;
10 | import org.math.plot.utils.Array;
11 |
12 | public class GridPlot3D extends Plot {
13 |
14 | double[] X;
15 | double[] Y;
16 | double[][] Z;
17 | private double[][] XYZ_list;
18 | public boolean draw_lines = true;
19 | public boolean fill_shape = true;
20 |
21 | public GridPlot3D(String n, Color c, double[] _X, double[] _Y, double[][] _Z) {
22 | super(n, c);
23 | X = _X;
24 | Y = _Y;
25 | Z = _Z;
26 | buildXYZ_list();
27 | }
28 |
29 | public void plot(AbstractDrawer draw, Color c) {
30 | if (!visible) {
31 | return;
32 | }
33 |
34 | draw.setColor(c);
35 |
36 | if (draw_lines) {
37 | draw.setLineType(AbstractDrawer.CONTINOUS_LINE);
38 | for (int i = 0; i < X.length; i++) {
39 | for (int j = 0; j < Y.length - 1; j++) {
40 | draw.drawLine(new double[]{X[i], Y[j], Z[j][i]}, new double[]{X[i], Y[j + 1], Z[j + 1][i]});
41 | }
42 | }
43 |
44 | for (int j = 0; j < Y.length; j++) {
45 | for (int i = 0; i < X.length - 1; i++) {
46 | draw.drawLine(new double[]{X[i], Y[j], Z[j][i]}, new double[]{X[i + 1], Y[j], Z[j][i + 1]});
47 | }
48 | }
49 | } else {
50 | draw.setDotType(AbstractDrawer.ROUND_DOT);
51 | draw.setDotRadius(AbstractDrawer.DEFAULT_DOT_RADIUS);
52 | for (int i = 0; i < X.length; i++) {
53 | for (int j = 0; j < Y.length; j++) {
54 | draw.drawDot(new double[]{X[i], Y[j], Z[j][i]});
55 | }
56 | }
57 | }
58 |
59 | if (fill_shape) {
60 | for (int j = 0; j < Y.length - 1; j++) {
61 | for (int i = 0; i < X.length - 1; i++) {
62 | draw.fillPolygon(0.2f, new double[]{X[i], Y[j], Z[j][i]}, new double[]{X[i + 1], Y[j], Z[j][i + 1]}, new double[]{X[i + 1], Y[j + 1],
63 | Z[j + 1][i + 1]}, new double[]{X[i], Y[j + 1], Z[j + 1][i]});
64 | }
65 | }
66 | }
67 | }
68 |
69 | private void buildXYZ_list() {
70 | XYZ_list = new double[X.length * Y.length][3];
71 | for (int i = 0; i < X.length; i++) {
72 | for (int j = 0; j < Y.length; j++) {
73 | XYZ_list[i + (j) * X.length][0] = X[i];
74 | XYZ_list[i + (j) * X.length][1] = Y[j];
75 | XYZ_list[i + (j) * X.length][2] = Z[j][i];
76 | }
77 | }
78 | }
79 |
80 | @Override
81 | public void setData(double[][] _Z) {
82 | datapanel=null;
83 | Z = _Z;
84 | buildXYZ_list();
85 | }
86 |
87 | @Override
88 | public double[][] getData() {
89 | return XYZ_list;
90 | }
91 |
92 | @Override
93 | public double[][] getBounds() {
94 | return new double[][]{{Array.min(X), Array.min(Y), Array.min(Array.min(Z))}, {Array.max(X), Array.max(Y), Array.max(Array.min(Z))}};
95 | }
96 |
97 | public void setDataZ(double[][] _Z) {
98 | setData(_Z);
99 | }
100 |
101 | public double[][] getDataZ() {
102 | return Z;
103 | }
104 |
105 | public void setDataX(double[] _X) {
106 | datapanel=null;
107 | X = _X;
108 | buildXYZ_list();
109 | }
110 |
111 | public double[] getDataX() {
112 | return X;
113 | }
114 |
115 | public void setDataY(double[] _Y) {
116 | datapanel=null;
117 | Y = _Y;
118 | buildXYZ_list();
119 | }
120 |
121 | public double[] getDataY() {
122 | return Y;
123 | }
124 |
125 | public void setDataXYZ(double[] _X, double[] _Y, double[][] _Z) {
126 | datapanel=null;
127 | X = _X;
128 | Y = _Y;
129 | Z = _Z;
130 | buildXYZ_list();
131 | }
132 |
133 | public double[] isSelected(int[] screenCoordTest, AbstractDrawer draw) {
134 | for (int i = 0; i < X.length; i++) {
135 | for (int j = 0; j < Y.length; j++) {
136 | double[] XY = {X[i], Y[j], Z[j][i]};
137 | int[] screenCoord = draw.project(XY);
138 |
139 | if ((screenCoord[0] + note_precision > screenCoordTest[0]) && (screenCoord[0] - note_precision < screenCoordTest[0])
140 | && (screenCoord[1] + note_precision > screenCoordTest[1]) && (screenCoord[1] - note_precision < screenCoordTest[1])) {
141 | return XY;
142 | }
143 | }
144 | }
145 | return null;
146 | }
147 |
148 | public static void main(String[] args) {
149 |
150 | int n = 14;
151 | int m = 16;
152 | Plot3DPanel p = new Plot3DPanel();
153 | double[] X = new double[n];
154 | double[] Y = new double[m];
155 | double[][] Z = new double[m][n];
156 |
157 | for (int i = 0; i < X.length; i++) {
158 | X[i] = 3 + i / (double) X.length;
159 | for (int j = 0; j < Y.length; j++) {
160 | Y[j] = 5 + j / (double) Y.length;
161 | Z[j][i] = Math.exp(X[i]) + Y[j];
162 | }
163 | }
164 | p.addGridPlot("toto", X, Y, Z);
165 |
166 | p.setLegendOrientation(PlotPanel.SOUTH);
167 | new FrameView(p);
168 | }
169 | }
--------------------------------------------------------------------------------
/src/main/java/org/math/plot/plots/HistogramPlot2D.java:
--------------------------------------------------------------------------------
1 | package org.math.plot.plots;
2 |
3 | import java.awt.*;
4 |
5 | import org.math.plot.*;
6 | import org.math.plot.render.*;
7 | import org.math.plot.utils.Array;
8 |
9 | public class HistogramPlot2D extends Plot {
10 |
11 | double[][] topLeft;
12 | double[][] topRight;
13 | double[][] bottomLeft;
14 | double[][] bottomRight;
15 | double[] widths;
16 | double width_constant = -1;
17 | double offsetCenter_perWidth;
18 | double factorWidth;
19 | boolean autowidth;
20 | boolean fill_shape = true;
21 | double[][] XY;
22 |
23 | public HistogramPlot2D(String n, Color c, double[][] _XY, double w) {
24 | this(n, c, _XY, w, 0.5, 1);
25 | }
26 |
27 | public HistogramPlot2D(String n, Color c, double[][] _XY, double[] w) {
28 | this(n, c, _XY, w, 0.5, 1);
29 | }
30 |
31 | // TODO Histogram group plots
32 | public HistogramPlot2D(String n, Color c, double[][] _XY, double w, double _offsetCenter_perWidth, double _factorWidth) {
33 | super(n, c);
34 | XY = _XY;
35 | width_constant = w;
36 |
37 | autowidth = false;
38 | offsetCenter_perWidth = _offsetCenter_perWidth;
39 | factorWidth = _factorWidth;
40 |
41 | build();
42 | }
43 |
44 | public HistogramPlot2D(String n, Color c, double[][] _XY, double[] w, double _offsetCenter_perWidth, double _factorWidth) {
45 | super(n, c);
46 | XY = _XY;
47 | widths = w;
48 |
49 | autowidth = false;
50 | offsetCenter_perWidth = _offsetCenter_perWidth;
51 | factorWidth = _factorWidth;
52 |
53 | build();
54 | }
55 |
56 | private void build() {
57 | if (width_constant > 0) {
58 | topLeft = new double[XY.length][];
59 | topRight = new double[XY.length][];
60 | bottomLeft = new double[XY.length][];
61 | bottomRight = new double[XY.length][];
62 | for (int i = 0; i < XY.length; i++) {
63 | topLeft[i] = new double[]{XY[i][0] - factorWidth * width_constant / 2 + (offsetCenter_perWidth - 0.5) * width_constant, XY[i][1]};
64 | topRight[i] = new double[]{XY[i][0] + factorWidth * width_constant / 2 + (offsetCenter_perWidth - 0.5) * width_constant, XY[i][1]};
65 | bottomLeft[i] = new double[]{XY[i][0] - factorWidth * width_constant / 2 + (offsetCenter_perWidth - 0.5) * width_constant, 0};
66 | bottomRight[i] = new double[]{XY[i][0] + factorWidth * width_constant / 2 + (offsetCenter_perWidth - 0.5) * width_constant, 0};
67 | }
68 | } else {
69 | topLeft = new double[XY.length][];
70 | topRight = new double[XY.length][];
71 | bottomLeft = new double[XY.length][];
72 | bottomRight = new double[XY.length][];
73 | for (int i = 0; i < XY.length; i++) {
74 | topLeft[i] = new double[]{XY[i][0] - factorWidth * widths[i] / 2 + (offsetCenter_perWidth - 0.5) * widths[i], XY[i][1]};
75 | topRight[i] = new double[]{XY[i][0] + factorWidth * widths[i] / 2 + (offsetCenter_perWidth - 0.5) * widths[i], XY[i][1]};
76 | bottomLeft[i] = new double[]{XY[i][0] - factorWidth * widths[i] / 2 + (offsetCenter_perWidth - 0.5) * widths[i], 0};
77 | bottomRight[i] = new double[]{XY[i][0] + factorWidth * widths[i] / 2 + (offsetCenter_perWidth - 0.5) * widths[i], 0};
78 | }
79 | }
80 | }
81 |
82 | /*
83 | * public HistogramPlot2D(double[][] XY, Color c, String n, ProjectionBase
84 | * b) { super(XY, c, n, PlotPanel.HISTOGRAM, b);
85 | *
86 | * autowidth = true;
87 | *
88 | * topLeft = new double[datas.length][]; topRight = new
89 | * double[datas.length][]; bottomLeft = new double[datas.length][];
90 | * bottomRight = new double[datas.length][];
91 | *
92 | * Sorting sort = new Sorting(DoubleArray.getColumnCopy(datas, 0), false);
93 | * datas = DoubleArray.getRowsCopy(XY, sort.getIndex());
94 | *
95 | * topLeft[0] = new double[] { datas[0][0] + (datas[0][0] - datas[1][0]) /
96 | * 2, datas[0][1] }; topRight[0] = new double[] { (datas[0][0] +
97 | * datas[1][0]) / 2, datas[0][1] }; bottomLeft[0] = new double[] {
98 | * datas[0][0] + (datas[0][0] - datas[1][0]) / 2, 0 }; bottomRight[0] = new
99 | * double[] { (datas[0][0] + datas[1][0]) / 2, 0 }; for (int i = 1; i <
100 | * datas.length - 1; i++) { topLeft[i] = new double[] { (datas[i][0] +
101 | * datas[i - 1][0]) / 2, datas[i][1] }; topRight[i] = new double[] {
102 | * (datas[i][0] + datas[i + 1][0]) / 2, datas[i][1] }; bottomLeft[i] = new
103 | * double[] { (datas[i][0] + datas[i - 1][0]) / 2, 0 }; bottomRight[i] = new
104 | * double[] { (datas[i][0] + datas[i + 1][0]) / 2, 0 }; }
105 | * topLeft[datas.length - 1] = new double[] { (datas[datas.length - 1][0] +
106 | * datas[datas.length - 2][0]) / 2, datas[datas.length - 1][1] };
107 | * topRight[datas.length - 1] = new double[] { datas[datas.length - 1][0] +
108 | * (datas[datas.length - 1][0] - datas[datas.length - 2][0]) / 2,
109 | * datas[datas.length - 1][1] }; bottomLeft[datas.length - 1] = new double[] {
110 | * (datas[datas.length - 1][0] + datas[datas.length - 2][0]) / 2, 0 };
111 | * bottomRight[datas.length - 1] = new double[] { datas[datas.length - 1][0] +
112 | * (datas[datas.length - 1][0] - datas[datas.length - 2][0]) / 2, 0 }; }
113 | */
114 | public void plot(AbstractDrawer draw, Color c) {
115 | if (!visible) {
116 | return;
117 | }
118 |
119 | draw.setColor(c);
120 | draw.setLineType(AbstractDrawer.CONTINOUS_LINE);
121 | for (int i = 0; i < XY.length; i++) {
122 | draw.drawLine(bottomLeft[i], topLeft[i]);
123 | draw.drawLine(topLeft[i], topRight[i]);
124 | draw.drawLine(topRight[i], bottomRight[i]);
125 | draw.drawLine(bottomRight[i], bottomLeft[i]);
126 |
127 | if (fill_shape) {
128 | draw.fillPolygon(0.2f, bottomLeft[i], topLeft[i], topRight[i], bottomRight[i]);
129 | }
130 | }
131 | }
132 |
133 | @Override
134 | public void setData(double[][] d) {
135 | datapanel = null;
136 | XY = d;
137 | }
138 |
139 | @Override
140 | public double[][] getData() {
141 | return XY;
142 | }
143 |
144 | @Override
145 | public double[][] getBounds() {
146 | return new double[][]{Array.min(bottomLeft), Array.max(topRight)};
147 | }
148 |
149 | public void setDataWidth(double[] w) {
150 | widths = w;
151 | width_constant = -1;
152 | build();
153 | }
154 |
155 | public void setDataWidth(double w) {
156 | width_constant = w;
157 | build();
158 | }
159 |
160 | public double[] getDataWidth() {
161 | if (width_constant > 0) {
162 | widths = new double[XY.length];
163 | for (int i = 0; i < widths.length; i++) {
164 | widths[i] = width_constant;
165 | }
166 | }
167 | return widths;
168 | }
169 |
170 | public void setData(double[][] d, double[] w) {
171 | setData(d);
172 | setDataWidth(w);
173 | }
174 |
175 | public void setData(double[][] d, double w) {
176 | setData(d);
177 | setDataWidth(w);
178 | }
179 |
180 | public double[] isSelected(int[] screenCoordTest, AbstractDrawer draw) {
181 | for (int i = 0; i < XY.length; i++) {
182 | int[] screenCoord = draw.project(XY[i]);
183 |
184 | if ((screenCoord[0] + note_precision > screenCoordTest[0]) && (screenCoord[0] - note_precision < screenCoordTest[0])
185 | && (screenCoord[1] + note_precision > screenCoordTest[1]) && (screenCoord[1] - note_precision < screenCoordTest[1])) {
186 | return XY[i];
187 | }
188 | }
189 | return null;
190 | }
191 |
192 | public static void main(String[] args) {
193 | double[] X = new double[500];
194 | for (int i = 0; i < X.length; i++) {
195 | X[i] = Math.random() + Math.random();
196 | }
197 | Plot2DPanel p = new Plot2DPanel("SOUTH");
198 | p.addHistogramPlot("test", X, 10);
199 | new FrameView(p);
200 | }
201 | }
--------------------------------------------------------------------------------
/src/main/java/org/math/plot/plots/HistogramPlot3D.java:
--------------------------------------------------------------------------------
1 | package org.math.plot.plots;
2 |
3 | import java.awt.*;
4 |
5 | import org.math.plot.*;
6 | import org.math.plot.render.*;
7 | import org.math.plot.utils.Array;
8 |
9 | public class HistogramPlot3D extends Plot {
10 |
11 | double[][] topNW;
12 | double[][] topNE;
13 | double[][] topSW;
14 | double[][] topSE;
15 | double[][] bottomNW;
16 | double[][] bottomNE;
17 | double[][] bottomSW;
18 | double[][] bottomSE;
19 | double[][] widths;
20 | double[] width_constant = {-1, -1};
21 | double[][] XY;
22 | boolean fill_shape = true;
23 |
24 | public HistogramPlot3D(String n, Color c, double[][] _XY, double[][] w) {
25 | super(n, c);
26 | XY = _XY;
27 | widths = w;
28 |
29 | build();
30 | }
31 |
32 | public HistogramPlot3D(String n, Color c, double[][] _XY, double wX, double wY) {
33 | super(n, c);
34 | XY = _XY;
35 | width_constant = new double[]{wX, wY};
36 |
37 | build();
38 | }
39 |
40 | public HistogramPlot3D(String n, Color c, double[][] _XY, double[] w) {
41 | super(n, c);
42 | XY = _XY;
43 | width_constant = w;
44 |
45 | build();
46 | }
47 |
48 | private void build() {
49 | if (width_constant[0] > 0) {
50 | topNW = new double[XY.length][];
51 | topNE = new double[XY.length][];
52 | topSW = new double[XY.length][];
53 | topSE = new double[XY.length][];
54 | bottomNW = new double[XY.length][];
55 | bottomNE = new double[XY.length][];
56 | bottomSW = new double[XY.length][];
57 | bottomSE = new double[XY.length][];
58 | for (int i = 0; i < XY.length; i++) {
59 | topNW[i] = new double[]{XY[i][0] - width_constant[0] / 2, XY[i][1] + width_constant[1] / 2, XY[i][2]};
60 | topNE[i] = new double[]{XY[i][0] + width_constant[0] / 2, XY[i][1] + width_constant[1] / 2, XY[i][2]};
61 | topSW[i] = new double[]{XY[i][0] - width_constant[0] / 2, XY[i][1] - width_constant[1] / 2, XY[i][2]};
62 | topSE[i] = new double[]{XY[i][0] + width_constant[0] / 2, XY[i][1] - width_constant[1] / 2, XY[i][2]};
63 | bottomNW[i] = new double[]{XY[i][0] - width_constant[0] / 2, XY[i][1] + width_constant[1] / 2, 0};
64 | bottomNE[i] = new double[]{XY[i][0] + width_constant[0] / 2, XY[i][1] + width_constant[1] / 2, 0};
65 | bottomSW[i] = new double[]{XY[i][0] - width_constant[0] / 2, XY[i][1] - width_constant[1] / 2, 0};
66 | bottomSE[i] = new double[]{XY[i][0] + width_constant[0] / 2, XY[i][1] - width_constant[1] / 2, 0};
67 | }
68 | } else {
69 | topNW = new double[XY.length][];
70 | topNE = new double[XY.length][];
71 | topSW = new double[XY.length][];
72 | topSE = new double[XY.length][];
73 | bottomNW = new double[XY.length][];
74 | bottomNE = new double[XY.length][];
75 | bottomSW = new double[XY.length][];
76 | bottomSE = new double[XY.length][];
77 | for (int i = 0; i < XY.length; i++) {
78 | topNW[i] = new double[]{XY[i][0] - widths[i][0] / 2, XY[i][1] + widths[i][1] / 2, XY[i][2]};
79 | topNE[i] = new double[]{XY[i][0] + widths[i][0] / 2, XY[i][1] + widths[i][1] / 2, XY[i][2]};
80 | topSW[i] = new double[]{XY[i][0] - widths[i][0] / 2, XY[i][1] - widths[i][1] / 2, XY[i][2]};
81 | topSE[i] = new double[]{XY[i][0] + widths[i][0] / 2, XY[i][1] - widths[i][1] / 2, XY[i][2]};
82 | bottomNW[i] = new double[]{XY[i][0] - widths[i][0] / 2, XY[i][1] + widths[i][1] / 2, 0};
83 | bottomNE[i] = new double[]{XY[i][0] + widths[i][0] / 2, XY[i][1] + widths[i][1] / 2, 0};
84 | bottomSW[i] = new double[]{XY[i][0] - widths[i][0] / 2, XY[i][1] - widths[i][1] / 2, 0};
85 | bottomSE[i] = new double[]{XY[i][0] + widths[i][0] / 2, XY[i][1] - widths[i][1] / 2, 0};
86 | }
87 | }
88 | }
89 |
90 | public void plot(AbstractDrawer draw, Color c) {
91 | if (!visible) {
92 | return;
93 | }
94 |
95 | draw.canvas.includeInBounds(bottomSW[0]);
96 | draw.canvas.includeInBounds(topNE[XY.length - 1]);
97 |
98 | draw.setColor(c);
99 | draw.setLineType(AbstractDrawer.CONTINOUS_LINE);
100 | for (int i = 0; i < XY.length; i++) {
101 | if (topNW[i][2] != bottomNW[i][2]) {
102 | draw.drawLine(topNW[i], topNE[i]);
103 | draw.drawLine(topNE[i], topSE[i]);
104 | draw.drawLine(topSE[i], topSW[i]);
105 | draw.drawLine(topSW[i], topNW[i]);
106 |
107 | draw.drawLine(bottomNW[i], bottomNE[i]);
108 | draw.drawLine(bottomNE[i], bottomSE[i]);
109 | draw.drawLine(bottomSE[i], bottomSW[i]);
110 | draw.drawLine(bottomSW[i], bottomNW[i]);
111 |
112 | draw.drawLine(bottomNW[i], topNW[i]);
113 | draw.drawLine(bottomNE[i], topNE[i]);
114 | draw.drawLine(bottomSE[i], topSE[i]);
115 | draw.drawLine(bottomSW[i], topSW[i]);
116 |
117 | if (fill_shape) {
118 | draw.fillPolygon(0.2f, topNW[i], topNE[i], topSE[i], topSW[i]);
119 | //draw.fillPolygon(bottomNW[i], bottomNE[i], bottomSE[i], bottomSW[i]);
120 | /*draw.fillPolygon(topNW[i], topNE[i], bottomNE[i], bottomNW[i]);
121 | draw.fillPolygon(topSW[i], topSE[i], bottomSE[i], bottomSW[i]);
122 | draw.fillPolygon(topNE[i], topSE[i], bottomSE[i], bottomNE[i]);
123 | draw.fillPolygon(topNW[i], topSW[i], bottomSW[i], bottomNW[i]);*/
124 | }
125 | }
126 | }
127 | }
128 |
129 | @Override
130 | public void setData(double[][] d) {
131 | datapanel = null;
132 | XY = d;
133 | }
134 |
135 | @Override
136 | public double[][] getData() {
137 | return XY;
138 | }
139 |
140 | @Override
141 | public double[][] getBounds() {
142 | return new double[][]{Array.min(bottomSW), Array.max(topNE)};
143 | }
144 |
145 | public void setDataWidth(double[][] w) {
146 | widths = w;
147 | }
148 |
149 | public void setDataWidth(double... w) {
150 | width_constant = w;
151 | build();
152 | }
153 |
154 | public double[][] getDataWidth() {
155 | if (width_constant[0] > 0) {
156 | widths = new double[XY.length][2];
157 | for (int i = 0; i < widths.length; i++) {
158 | widths[i][0] = width_constant[0];
159 | widths[i][1] = width_constant[1];
160 | }
161 | }
162 | return widths;
163 | }
164 |
165 | public void setData(double[][] d, double[][] w) {
166 | setData(d);
167 | widths = w;
168 | }
169 |
170 | public void setData(double[][] d, double... w) {
171 | setData(d);
172 | setDataWidth(w);
173 | }
174 |
175 | public double[] isSelected(int[] screenCoordTest, AbstractDrawer draw) {
176 | for (int i = 0; i < XY.length; i++) {
177 | int[] screenCoord = draw.project(XY[i]);
178 |
179 | if ((screenCoord[0] + note_precision > screenCoordTest[0]) && (screenCoord[0] - note_precision < screenCoordTest[0])
180 | && (screenCoord[1] + note_precision > screenCoordTest[1]) && (screenCoord[1] - note_precision < screenCoordTest[1])) {
181 | return XY[i];
182 | }
183 | }
184 | return null;
185 | }
186 |
187 | public static void main(String[] args) {
188 | double[][] XY = new double[500][2];
189 | for (int i = 0; i < XY.length; i++) {
190 | XY[i][0] = Math.random() + Math.random();
191 | XY[i][1] = Math.random() + Math.random();
192 | }
193 | Plot3DPanel p = new Plot3DPanel("SOUTH");
194 | p.addHistogramPlot("test", XY, 4, 6);
195 | new FrameView(p);
196 | }
197 | }
--------------------------------------------------------------------------------
/src/main/java/org/math/plot/plots/LayerPlot.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Created on 5 juil. 07 by richet
3 | */
4 | package org.math.plot.plots;
5 |
6 | import org.math.plot.DataPanel;
7 | import org.math.plot.canvas.PlotCanvas;
8 | import org.math.plot.render.*;
9 |
10 | public abstract class LayerPlot extends Plot {
11 |
12 | Plot plot;
13 |
14 | public LayerPlot(String name, Plot p) {
15 | super(name, p.color);
16 | plot = p;
17 | }
18 |
19 | public double[] isSelected(int[] screenCoordTest, AbstractDrawer draw) {
20 | return null;
21 | }
22 |
23 | @Override
24 | public double[][] getBounds() {
25 | return plot.getBounds();
26 | }
27 |
28 | @Override
29 | public DataPanel getDataPanel(PlotCanvas plotCanvas) {
30 | return null;
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/src/main/java/org/math/plot/plots/LinePlot.java:
--------------------------------------------------------------------------------
1 | package org.math.plot.plots;
2 |
3 | import java.awt.*;
4 |
5 | import javax.swing.*;
6 |
7 | import org.math.plot.*;
8 | import org.math.plot.render.*;
9 |
10 | public class LinePlot extends ScatterPlot {
11 |
12 | public boolean draw_dot = false;
13 |
14 | public LinePlot(String n, Color c, boolean[][] _pattern, double[][] _XY) {
15 | super(n, c, _pattern, _XY);
16 | }
17 |
18 | public LinePlot(String n, Color c, int _type, int _radius, double[][] _XY) {
19 | super(n, c, _type, _radius, _XY);
20 | }
21 |
22 | public LinePlot(String n, Color c, double[][] _XY) {
23 | super(n, c, _XY);
24 | }
25 |
26 | public void plot(AbstractDrawer draw, Color c) {
27 | if (!visible)
28 | return;
29 |
30 | if (draw_dot)
31 | super.plot(draw, c);
32 |
33 | draw.setColor(c);
34 | draw.setLineType(AbstractDrawer.CONTINOUS_LINE);
35 | for (int i = 0; i < XY.length - 1; i++)
36 | if (!anyNaN(XY[i]) && !anyNaN(XY[i+1]))
37 | draw.drawLine(XY[i], XY[i + 1]);
38 | }
39 |
40 | boolean anyNaN(double[] xy) {
41 | for (int i = 0; i < xy.length; i++) {
42 | if(Double.isNaN(xy[i])) return true;
43 | }
44 | return false;
45 | }
46 |
47 | public static void main(String[] args) {
48 | Plot2DPanel p2 = new Plot2DPanel();
49 |
50 | double[][] XYZ = new double[100][2];
51 | for (int j = 0; j < XYZ.length; j++) {
52 | XYZ[j][0] = 2*Math.PI*(double)j/XYZ.length;
53 | XYZ[j][1] = Math.sin(XYZ[j][0]);
54 | }
55 | XYZ[50][0] = Double.NaN;
56 | p2.addLinePlot("sin" , XYZ);
57 |
58 |
59 | p2.setLegendOrientation(PlotPanel.SOUTH);
60 | new FrameView(p2).setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
61 |
62 | Plot3DPanel p = new Plot3DPanel();
63 |
64 | XYZ = new double[100][3];
65 | for (int j = 0; j < XYZ.length; j++) {
66 | XYZ[j][0] = 2*Math.PI*(double)j/XYZ.length;
67 | XYZ[j][1] = Math.sin(XYZ[j][0]);
68 | XYZ[j][2] = Math.sin(XYZ[j][0])*Math.cos(XYZ[j][1]);
69 | }
70 | p.addLinePlot("toto" , XYZ);
71 |
72 | p.setLegendOrientation(PlotPanel.SOUTH);
73 | new FrameView(p).setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
74 | }
75 | }
--------------------------------------------------------------------------------
/src/main/java/org/math/plot/plots/QuantileLayerPlot.java:
--------------------------------------------------------------------------------
1 | package org.math.plot.plots;
2 |
3 | import java.awt.Color;
4 |
5 | import javax.swing.JFrame;
6 |
7 | import org.math.plot.FrameView;
8 | import org.math.plot.Plot2DPanel;
9 | import org.math.plot.render.AbstractDrawer;
10 | import org.math.plot.utils.Array;
11 |
12 | /**
13 | * @author Yann RICHET
14 | * @version 1.0
15 | */
16 |
17 | public class QuantileLayerPlot extends LayerPlot {
18 |
19 | public static int WIDTH = 2;
20 |
21 | int axe;
22 |
23 | double quantileRate;
24 |
25 | Color gradC;
26 |
27 | double main_data_constant = 0;
28 |
29 | public boolean symetric = false;
30 |
31 | double[] Q;
32 |
33 | //public static double DEFAULT_RATE=1.0;
34 |
35 | /*public QuantilePlot(Plot p, int a, double[] q, boolean _symetric) {
36 | this(p, a, q, DEFAULT_RATE,_symetric);
37 |
38 | }*/
39 |
40 | public QuantileLayerPlot(Plot p, int a, double q, double r, boolean _symetric) {
41 | this(p, a, null, r, true);
42 | main_data_constant = q;
43 | }
44 |
45 | /*public QuantilePlot(Plot p, int a, double q) {
46 | this(p, a, q, DEFAULT_RATE,true);
47 | }*/
48 |
49 | /** Build a quantile plot based on given plot. The quantile is drawn as a linear gradient from the base plot dots.
50 | * @param p base plot
51 | * @param a axis number of quantile : 0=X quantile, 1=Y quantile, 2=Z quantile
52 | * @param q array of quantiles values
53 | * @param r rate of the quantile. The gradient line length is q/r
54 | * @param _symetric if yes, quantiles are drawn on both negative and positive sides of base plot dots
55 | */
56 | public QuantileLayerPlot(Plot p, int a, double[] q, double r, boolean _symetric) {
57 | super(r + " quantile of " + p.name, p);
58 | if (q != null)
59 | Array.checkLength(q, p.getData().length);
60 | Q = q;
61 | axe = a;
62 | quantileRate = r;
63 | symetric = _symetric;
64 |
65 | }
66 |
67 | public double getQuantilesValue(int numCoord) {
68 | return Q[numCoord];
69 | }
70 |
71 | public int getAxe() {
72 | return axe;
73 | }
74 |
75 | public double getQuantileRate() {
76 | return quantileRate;
77 | }
78 |
79 | public void plot(AbstractDrawer draw, Color c) {
80 | if (!plot.visible)
81 | return;
82 |
83 | draw.setColor(c);
84 | gradC = new Color(c.getRed(), c.getGreen(), c.getBlue(), (int) (255 * (1 - quantileRate)));
85 |
86 | draw.setLineType(AbstractDrawer.CONTINOUS_LINE);
87 | draw.setLineWidth(WIDTH);
88 | if (main_data_constant == 0)
89 | for (int i = 0; i < plot.getData().length; i++) {
90 | double[] d = Array.getRowCopy(plot.getData(), i);
91 | d[axe] += Q[i];///quantileRate;
92 | draw.setGradient(plot.getData()[i], c, d, gradC);
93 | draw.drawLine(plot.getData()[i], d);
94 | // draw.drawDot(d, RADIUS/*(int)(RADIUS*quantileRate)*/);
95 |
96 | if (symetric) {
97 | d[axe] -= 2 * Q[i];///quantileRate;
98 | draw.setGradient(plot.getData()[i], c, d, gradC);
99 | draw.drawLine(plot.getData()[i], d);
100 | // draw.drawDot(d, RADIUS/*(int)(RADIUS*quantileRate)*/);
101 | }
102 | }
103 | else
104 | for (int i = 0; i < plot.getData().length; i++) {
105 | double[] d = Array.getRowCopy(plot.getData(), i);
106 | d[axe] += main_data_constant;///quantileRate;
107 | draw.setGradient(plot.getData()[i], c, d, gradC);
108 | draw.drawLine(plot.getData()[i], d);
109 | // draw.drawDot(d, shape/*RADIUS/*(int)(RADIUS*quantileRate)*/);
110 |
111 | if (symetric) {
112 | d[axe] -= 2 * main_data_constant;///quantileRate;
113 | draw.setGradient(plot.getData()[i], c, d, gradC);
114 | draw.drawLine(plot.getData()[i], d);
115 | // draw.drawDot(d, RADIUS/*(int)(RADIUS*quantileRate)*/);
116 | }
117 | }
118 | draw.resetGradient();
119 | draw.setLineWidth(AbstractDrawer.DEFAULT_LINE_WIDTH);
120 |
121 | }
122 |
123 | @Override
124 | public void setData(double[][] d) {
125 | Q = d[0];
126 | }
127 |
128 | @Override
129 | public double[][] getData() {
130 | return new double[][] { Q };
131 | }
132 |
133 | public static void main(String[] args) {
134 | Plot2DPanel p2 = new Plot2DPanel();
135 | for (int i = 0; i < 1; i++) {
136 | double[][] XYZ = new double[10][2];
137 | for (int j = 0; j < XYZ.length; j++) {
138 | XYZ[j][0] = /*1 + */Math.random();
139 | XYZ[j][1] = /*100 * */Math.random();
140 | }
141 | p2.addScatterPlot("toto" + i, XYZ);
142 | }
143 | p2.addQuantiletoPlot(0, 1, 1.0, true, 0.2);
144 | new FrameView(p2).setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
145 | }
146 | }
--------------------------------------------------------------------------------
/src/main/java/org/math/plot/plots/ScatterPlot.java:
--------------------------------------------------------------------------------
1 | package org.math.plot.plots;
2 |
3 | import java.awt.*;
4 |
5 | import javax.swing.*;
6 |
7 | import org.math.plot.*;
8 | import org.math.plot.canvas.PlotCanvas;
9 | import org.math.plot.render.*;
10 | import org.math.plot.utils.Array;
11 | import org.math.plot.utils.FastMath;
12 |
13 | public class ScatterPlot extends Plot {
14 |
15 | private int type;
16 | private int radius;
17 | private boolean[][] pattern;
18 | private boolean use_pattern;
19 | double[][] XY;
20 | private String[] tags;
21 |
22 | public ScatterPlot(String n, Color c, boolean[][] _pattern, double[][] _XY) {
23 | super(n, c);
24 | XY = _XY;
25 | use_pattern = true;
26 | pattern = _pattern;
27 | }
28 |
29 | public ScatterPlot(String n, Color c, int _type, int _radius, double[][] _XY) {
30 | super(n, c);
31 | XY = _XY;
32 | use_pattern = false;
33 | type = _type;
34 | radius = _radius;
35 | }
36 |
37 | public ScatterPlot(String n, Color c, double[][] _XY) {
38 | this(n, c, AbstractDrawer.ROUND_DOT, AbstractDrawer.DEFAULT_DOT_RADIUS, _XY);
39 | }
40 |
41 | public void plot(AbstractDrawer draw, Color c) {
42 | if (!visible) {
43 | return;
44 | }
45 |
46 | draw.setColor(c);
47 | if (use_pattern) {
48 | draw.setDotType(AbstractDrawer.PATTERN_DOT);
49 | draw.setDotPattern(pattern);
50 | } else {
51 | draw.setDotRadius(radius);
52 | if (type == AbstractDrawer.CROSS_DOT) {
53 | draw.setDotType(AbstractDrawer.CROSS_DOT);
54 | } else {
55 | draw.setDotType(AbstractDrawer.ROUND_DOT);
56 | }
57 | }
58 |
59 | for (int i = 0; i < XY.length; i++) {
60 | draw.drawDot(XY[i]);
61 | }
62 | }
63 |
64 | public void setDotPattern(int t) {
65 | type = t;
66 | use_pattern = false;
67 | }
68 |
69 | public void setDotPattern(boolean[][] t) {
70 | use_pattern = true;
71 | pattern = t;
72 | }
73 |
74 | @Override
75 | public void setData(double[][] d) {
76 | datapanel = null;
77 | XY = d;
78 | }
79 |
80 | @Override
81 | public double[][] getData() {
82 | return XY;
83 | }
84 |
85 | @Override
86 | public double[][] getBounds() {
87 | return Array.mergeRows(Array.min(XY), Array.max(XY));
88 | }
89 |
90 | public double[] isSelected(int[] screenCoordTest, AbstractDrawer draw) {
91 | for (int i = 0; i < XY.length; i++) {
92 | int[] screenCoord = draw.project(XY[i]);
93 |
94 | if (FastMath.abs(screenCoord[0] - screenCoordTest[0]) < note_precision && FastMath.abs(screenCoord[1] - screenCoordTest[1]) < note_precision) {
95 | return XY[i];
96 | }
97 | }
98 | return null;
99 | }
100 |
101 | public static void main(String[] args) {
102 | Plot2DPanel p2 = new Plot2DPanel();
103 | for (int i = 0; i < 3; i++) {
104 | double[][] XYZ = new double[10][2];
105 | for (int j = 0; j < XYZ.length; j++) {
106 | XYZ[j][0] = /*1 + */ Math.random();
107 | XYZ[j][1] = /*100 * */ Math.random();
108 | }
109 | p2.addScatterPlot("toto" + i, XYZ);
110 | }
111 |
112 | p2.setLegendOrientation(PlotPanel.SOUTH);
113 | new FrameView(p2).setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
114 |
115 | Plot3DPanel p = new Plot3DPanel();
116 | String[] tags = null;
117 | for (int i = 0; i < 3; i++) {
118 | double[][] XYZ = new double[10][3];
119 | tags = new String[10];
120 | for (int j = 0; j < XYZ.length; j++) {
121 | XYZ[j][0] = /*1 +*/ 2.5 * Math.random();
122 | XYZ[j][1] = /*100 **/ Math.random();
123 | XYZ[j][2] = /*0.0001 **/ Math.random();
124 | tags[j] = "tags " + j;
125 | }
126 | p.addScatterPlot("toto" + i, XYZ);
127 | }
128 | ((ScatterPlot) p.getPlot(0)).setTags(tags);
129 |
130 | p.setLegendOrientation(PlotPanel.SOUTH);
131 | new FrameView(p).setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
132 | }
133 |
134 | /**
135 | * @param tags the tags to set
136 | */
137 | public void setTags(String[] tags) {
138 | datapanel = null;
139 | this.tags = tags;
140 | }
141 |
142 | @Override
143 | public void noteCoord(AbstractDrawer draw, double[] coordNoted) {
144 | if (coordNoted == null) {
145 | return;
146 | }
147 |
148 | if (tags == null) {
149 | super.noteCoord(draw, coordNoted);
150 | } else {
151 | draw.setColor(PlotCanvas.NOTE_COLOR);
152 | for (int i = 0; i < XY.length; i++) {
153 | if (tags.length > i) {
154 | if (Array.equals(XY[i], coordNoted)) {
155 | draw.drawShadowedText(tags[i], .5f, coordNoted);
156 | }
157 | }
158 | }
159 | }
160 | //draw.drawCoordinate(coordNoted);
161 | //draw.drawText(Array.cat(draw.canvas.reverseMapedData(coordNoted)), coordNoted);
162 | }
163 | }
--------------------------------------------------------------------------------
/src/main/java/org/math/plot/plots/StaircasePlot.java:
--------------------------------------------------------------------------------
1 | package org.math.plot.plots;
2 |
3 | import java.awt.*;
4 |
5 | import javax.swing.*;
6 |
7 | import org.math.plot.*;
8 | import org.math.plot.render.*;
9 |
10 | public class StaircasePlot extends ScatterPlot {
11 |
12 | public boolean link = true;
13 |
14 | public StaircasePlot(String n, Color c, boolean[][] _pattern, double[][] _XY) {
15 | super(n, c, _pattern, _XY);
16 | }
17 |
18 | public StaircasePlot(String n, Color c, int _type, int _radius, double[][] _XY) {
19 | super(n, c, _type, _radius, _XY);
20 | }
21 |
22 | public StaircasePlot(String n, Color c, double[][] _XY) {
23 | super(n, c, _XY);
24 | }
25 |
26 | public void plot(AbstractDrawer draw, Color c) {
27 | if (!visible)
28 | return;
29 |
30 | //System.out.println(Array.toString(XY));
31 |
32 | draw.setColor(c);
33 | draw.setLineType(AbstractDrawer.CONTINOUS_LINE);
34 | for (int i = 0; i < XY.length - 1; i++) {
35 | double[] begin = XY[i].clone();
36 | double[] end = XY[i + 1].clone();
37 | end[end.length - 1] = XY[i][end.length - 1];
38 | draw.drawLine(begin, end);
39 | }
40 |
41 | //System.out.println(Array.toString(XY));
42 |
43 | if (link) {
44 | for (int i = 0; i < XY.length - 2; i++) {
45 | double[] begin = XY[i+1].clone();
46 | double[] end = XY[i + 1].clone();
47 | begin[begin.length - 1] = XY[i][begin.length - 1];
48 | draw.drawLine(begin, end);
49 | }
50 | }
51 | //System.out.println(Array.toString(XY));
52 |
53 | }
54 |
55 | public static void main(String[] args) {
56 | Plot2DPanel p = new Plot2DPanel();
57 |
58 | double[] X = new double[10];
59 | double[] Y = new double[10];
60 | for (int j = 0; j < X.length; j++) {
61 | X[j] = j;
62 | Y[j] = Math.random();
63 | }
64 | p.addStaircasePlot("toto", X,Y);
65 |
66 | new FrameView(p).setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
67 | }
68 |
69 | }
--------------------------------------------------------------------------------
/src/main/java/org/math/plot/plots/VectorLayerPlot.java:
--------------------------------------------------------------------------------
1 | package org.math.plot.plots;
2 |
3 | import java.awt.*;
4 |
5 | import javax.swing.*;
6 |
7 | import org.math.plot.*;
8 | import org.math.plot.render.*;
9 | import org.math.plot.utils.*;
10 |
11 | /**
12 | * @author Yann RICHET
13 | * @version 1.0
14 | */
15 |
16 | /**Layer to add a vector field to an existing Plot*/
17 | public class VectorLayerPlot extends LayerPlot {
18 |
19 | public static int RADIUS = 5;
20 |
21 | double[][] V;
22 |
23 | /**Create a vector fiels based on data of a plot
24 | @param p Base plot to support vector field
25 | @param v Vector field of same lenght that p data */
26 | public VectorLayerPlot(Plot p, double[][] v) {
27 | super("Vector of " + p.name, p);
28 | if (v != null) {
29 | Array.checkRowDimension(v, p.getData().length);
30 | Array.checkColumnDimension(v, p.getData()[0].length);
31 | }
32 | V = v;
33 |
34 | }
35 |
36 | @Override
37 | public void setData(double[][] v) {
38 | V = v;
39 | }
40 |
41 | @Override
42 | public double[][] getData() {
43 | return V;
44 | }
45 |
46 | public void plot(AbstractDrawer draw, Color c) {
47 | if (!plot.visible)
48 | return;
49 |
50 | draw.setColor(c);
51 |
52 | draw.setLineType(AbstractDrawer.CONTINOUS_LINE);
53 |
54 | for (int i = 0; i < plot.getData().length; i++) {
55 | double[] d = Array.getRowCopy(plot.getData(), i);
56 | for (int j = 0; j < d.length; j++) {
57 | d[j] += V[i][j];
58 | }
59 | draw.drawLine(plot.getData()[i], d);
60 | //TODO: draw arrow at position d
61 |
62 | }
63 |
64 | }
65 |
66 | public static void main(String[] args) {
67 | Plot2DPanel p2 = new Plot2DPanel();
68 | double[][] XYZ = new double[100][2];
69 | double[][] dXYZ = new double[100][2];
70 |
71 | for (int j = 0; j < XYZ.length; j++) {
72 | XYZ[j][0] = Math.random()*10;
73 | XYZ[j][1] = Math.random()*10;
74 | dXYZ[j][0] = 1.0/Math.sqrt(1+Math.log(XYZ[j][0])*Math.log(XYZ[j][0]));
75 | dXYZ[j][1] = Math.log(XYZ[j][0])/Math.sqrt(1+Math.log(XYZ[j][0])*Math.log(XYZ[j][0]));
76 | }
77 | p2.addScatterPlot("toto", XYZ);
78 |
79 | p2.addVectortoPlot(0, dXYZ);
80 | new FrameView(p2).setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
81 | }
82 | }
--------------------------------------------------------------------------------
/src/main/java/org/math/plot/render/AWTDrawer2D.java:
--------------------------------------------------------------------------------
1 | package org.math.plot.render;
2 |
3 | import org.math.plot.canvas.*;
4 |
5 | public class AWTDrawer2D extends AWTDrawer {
6 |
7 | public AWTDrawer2D(PlotCanvas _canvas) {
8 | super(_canvas);
9 | projection = new Projection2D(this);
10 | }
11 |
12 | /*// More efficient method for orthogonal display of images
13 | public void drawImage(Image img,float alpha, double[] _xyzSW, double[] _xyzSE,double[] _xyzNW) {
14 | int[] cornerNW = projection.screenProjection(_xyzNW);
15 | int[] cornerSE = projection.screenProjection(_xyzSE);
16 | int[] cornerSW = projection.screenProjection(_xyzSW);
17 |
18 | AffineTransform transform = new AffineTransform();
19 | transform.translate(cornerNW[0],cornerNW[1]);
20 | transform.scale((-cornerSW[0]+cornerSE[0])/(double)img.getWidth(canvas),(-cornerNW[1]+cornerSW[1])/(double)img.getHeight(canvas));
21 |
22 | Composite cs = comp2D.getComposite();
23 | comp2D.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER,alpha));
24 | comp2D.drawImage(img, transform,canvas);
25 | comp2D.setComposite(cs);
26 | }*/
27 |
28 | }
29 |
--------------------------------------------------------------------------------
/src/main/java/org/math/plot/render/AWTDrawer3D.java:
--------------------------------------------------------------------------------
1 | package org.math.plot.render;
2 |
3 | import org.math.plot.canvas.*;
4 |
5 | public class AWTDrawer3D extends AWTDrawer {
6 |
7 | public AWTDrawer3D(PlotCanvas _canvas) {
8 | super(_canvas);
9 | projection = new Projection3D(this);
10 | }
11 |
12 | public void rotate(int[] t, int[] panelSize) {
13 | ((Projection3D) projection).rotate(t, panelSize);
14 | }
15 |
16 | public void dilate(int[] screenOrigin, double[] screenRatio) {
17 | super.dilate(screenOrigin, screenRatio);
18 | ((Projection3D) projection).updateCoordsCenterScreen();
19 | canvas.repaint();
20 | }
21 |
22 | public void translate(int... t) {
23 | super.translate(t);
24 | ((Projection3D) projection).updateCoordsCenterScreen();
25 | canvas.repaint();
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/src/main/java/org/math/plot/render/Projection.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Created on 31 mai 2005 by richet
3 | */
4 | package org.math.plot.render;
5 |
6 | import org.math.plot.plotObjects.*;
7 | import org.math.plot.utils.FastMath;
8 |
9 | public abstract class Projection {
10 |
11 | protected int[][] baseScreenCoords;
12 | public static double DEFAULT_BORDER = 0.15;
13 | protected double borderCoeff = 1 - 2 * DEFAULT_BORDER;
14 | protected AWTDrawer draw;
15 |
16 | public Projection(AWTDrawer _draw) {
17 | draw = _draw;
18 | }
19 |
20 | public void initBaseCoordsProjection(boolean reset) {
21 | // System.out.println("Projection.initBaseCoordsProjection");
22 | if (baseScreenCoords == null) {
23 | baseScreenCoords = new int[draw.canvas.base.baseCoords.length][2];
24 | }
25 | if (reset) {
26 | totalScreenRatio[0] = 1;
27 | totalScreenRatio[1] = 1;
28 | }
29 | for (int i = 0; i < draw.canvas.base.dimension + 1; i++) {
30 | // Compute the basis extremity coordinates in the normed-centered screen (ie [-0.5,0.5]x[-0.5,0.5] screen)
31 | double[] ratio = new double[]{1,1};
32 | if (draw.canvas.base.baseCoords!=null)
33 | ratio = baseCoordsScreenProjectionRatio(draw.canvas.base.baseCoords[i]);
34 | // Compute the basis extremity coordinates in the true screen (ie in px: [0,400]x[0,400])
35 | baseScreenCoords[i][0] = (int) (draw.canvas.getWidth() * (.5 + (borderCoeff * ratio[0] / totalScreenRatio[0])));
36 | baseScreenCoords[i][1] = (int) (draw.canvas.getHeight() * (.5 - (borderCoeff * ratio[1] / totalScreenRatio[1])));
37 | }
38 | //System.err.println("\n" + Array.toString(baseScreenCoords));
39 | }
40 |
41 | // ///////////////////////////////////////////
42 | // ////// move methods ///////////////////////
43 | // ///////////////////////////////////////////
44 | public void translate(int[] screenTranslation) {
45 | for (int i = 0; i < draw.canvas.base.dimension + 1; i++) {
46 | baseScreenCoords[i][0] = baseScreenCoords[i][0] + screenTranslation[0];
47 | baseScreenCoords[i][1] = baseScreenCoords[i][1] + screenTranslation[1];
48 | }
49 | }
50 | // This stores the whole zooming ratio along all dilate calls.
51 | public double[] totalScreenRatio = new double[]{1, 1};
52 | public double[] maxScreenRatio = new double[]{1, 1};
53 | public double[] minScreenRatio = new double[]{.01, .01};
54 |
55 | public void dilate(int[] screenOrigin, double[] screenRatio) {
56 | // System.out.println("screenOrigin = "+screenOrigin[0]+" ,
57 | // "+screenOrigin[1]);
58 | // System.out.println("screenRatio = "+screenRatio[0]+" ,
59 | // "+screenRatio[1]);
60 |
61 | // Update the zooming ratio history
62 | if (totalScreenRatio[0] * screenRatio[0] > maxScreenRatio[0]) screenRatio[0] = maxScreenRatio[0]/totalScreenRatio[0];
63 | if (totalScreenRatio[1] * screenRatio[1] > maxScreenRatio[1]) screenRatio[1] = maxScreenRatio[1]/totalScreenRatio[1];
64 |
65 | if (totalScreenRatio[0] * screenRatio[0] < minScreenRatio[0]) screenRatio[0] = minScreenRatio[0]/totalScreenRatio[0];
66 | if (totalScreenRatio[1] * screenRatio[1] < minScreenRatio[1]) screenRatio[1] = minScreenRatio[1]/totalScreenRatio[1];
67 |
68 | for (int i = 0; i < draw.canvas.base.dimension + 1; i++) {
69 | // System.out.println("baseScreenCoords["+i+"] =
70 | // "+baseScreenCoords[i][0]+" , "+baseScreenCoords[i][1]);
71 | baseScreenCoords[i][0] = (int) ((baseScreenCoords[i][0] - screenOrigin[0]) / screenRatio[0]);
72 | baseScreenCoords[i][1] = (int) ((baseScreenCoords[i][1] - screenOrigin[1]) / screenRatio[1]);
73 | // System.out.println(" -> baseScreenCoords["+i+"] =
74 | // "+baseScreenCoords[i][0]+" , "+baseScreenCoords[i][1]);
75 | }
76 | // Update the zooming ratio history
77 | totalScreenRatio[0] = totalScreenRatio[0] * screenRatio[0];
78 | totalScreenRatio[1] = totalScreenRatio[1] * screenRatio[1];
79 | }
80 |
81 | // ///////////////////////////////////////////
82 | // ////// projection method //////////////////
83 | // ///////////////////////////////////////////
84 | public int[] screenProjection(double... pC) {
85 | // System.out.println("Projection.screenProjection("+Array.toString(pC)+")");
86 | double[] sC = new double[2];
87 | sC[0] = baseScreenCoords[0][0];
88 | sC[1] = baseScreenCoords[0][1];
89 | for (int i = 0; i < draw.canvas.base.dimension; i++) {
90 | double normdist_pC_baseCoords = 0;
91 | if (draw.canvas.base.axesScales[i].equalsIgnoreCase(Base.LOGARITHM)) {
92 | normdist_pC_baseCoords = ((FastMath.log(pC[i]) - FastMath.log(draw.canvas.base.baseCoords[0][i])) / (FastMath.log(draw.canvas.base.baseCoords[i + 1][i]) - FastMath.log(draw.canvas.base.baseCoords[0][i])));
93 | } else if (draw.canvas.base.axesScales[i].equalsIgnoreCase(Base.LINEAR) || draw.canvas.base.axesScales[i].equalsIgnoreCase(Base.STRINGS)) {
94 | if(pC!=null && draw.canvas.base.baseCoords!=null && draw.canvas.base.baseCoords[i+1] != null)
95 | normdist_pC_baseCoords = ((pC[i] - draw.canvas.base.baseCoords[0][i]) / (draw.canvas.base.baseCoords[i + 1][i] - draw.canvas.base.baseCoords[0][i]));
96 | }
97 | sC[0] += normdist_pC_baseCoords * (baseScreenCoords[i + 1][0] - baseScreenCoords[0][0]);
98 | sC[1] += normdist_pC_baseCoords * (baseScreenCoords[i + 1][1] - baseScreenCoords[0][1]);
99 | }
100 |
101 | if (draw.base_offset != null) {
102 | for (int i = 0; i < draw.canvas.base.dimension; i++) {
103 | sC[0] += draw.base_offset[i] * (baseScreenCoords[i + 1][0] - baseScreenCoords[0][0]);
104 | sC[1] += draw.base_offset[i] * (baseScreenCoords[i + 1][1] - baseScreenCoords[0][1]);
105 | }
106 | }
107 |
108 | if (draw.screen_offset != null) {
109 | sC[0] += draw.screen_offset[0];
110 | sC[1] += draw.screen_offset[1];
111 | }
112 |
113 | return new int[]{(int) sC[0], (int) sC[1]};
114 | }
115 |
116 | public int[] screenProjectionBase(double... rC) {
117 | double[] sC = new double[2];
118 | sC[0] = baseScreenCoords[0][0];
119 | sC[1] = baseScreenCoords[0][1];
120 | for (int i = 0; i < draw.canvas.base.dimension; i++) {
121 | sC[0] += rC[i] * (baseScreenCoords[i + 1][0] - baseScreenCoords[0][0]);
122 | sC[1] += rC[i] * (baseScreenCoords[i + 1][1] - baseScreenCoords[0][1]);
123 | }
124 |
125 | if (draw.base_offset != null) {
126 | for (int i = 0; i < draw.canvas.base.dimension; i++) {
127 | sC[0] += draw.base_offset[i] * (baseScreenCoords[i + 1][0] - baseScreenCoords[0][0]);
128 | sC[1] += draw.base_offset[i] * (baseScreenCoords[i + 1][1] - baseScreenCoords[0][1]);
129 | }
130 | }
131 |
132 | if (draw.screen_offset != null) {
133 | sC[0] += draw.screen_offset[0];
134 | sC[1] += draw.screen_offset[1];
135 | }
136 |
137 | return new int[]{(int) sC[0], (int) sC[1]};
138 | }
139 |
140 | protected abstract double[] baseCoordsScreenProjectionRatio(double[] xyz);
141 | }
142 |
--------------------------------------------------------------------------------
/src/main/java/org/math/plot/render/Projection2D.java:
--------------------------------------------------------------------------------
1 | package org.math.plot.render;
2 |
3 | /**
4 | * BSD License
5 | *
6 | * @author Yann RICHET
7 | */
8 | public class Projection2D extends Projection {
9 |
10 | public Projection2D(AWTDrawer _draw) {
11 | super(_draw);
12 | initBaseCoordsProjection(true);
13 | }
14 |
15 | protected double[] baseCoordsScreenProjectionRatio(double[] xy) {
16 | double[] sC = new double[2];
17 | sC[0] = -0.5+(xy[0] - draw.canvas.base.roundXmin[0]) / (draw.canvas.base.roundXmax[0] - draw.canvas.base.roundXmin[0]);
18 | sC[1] = -0.5+(xy[1] - draw.canvas.base.roundXmin[1]) / (draw.canvas.base.roundXmax[1] - draw.canvas.base.roundXmin[1]);
19 | // System.out.println("(" + xy[0] +"," + xy[1] + ") -> (" + sC[0] + ","
20 | // + sC[1] + ")");
21 | return sC;
22 | }
23 | }
--------------------------------------------------------------------------------
/src/main/java/org/math/plot/render/Projection3D.java:
--------------------------------------------------------------------------------
1 | package org.math.plot.render;
2 |
3 | import org.math.plot.utils.FastMath;
4 |
5 | /**
6 | * BSD License
7 | *
8 | * @author Yann RICHET
9 | */
10 | public class Projection3D extends Projection {
11 |
12 | public double theta;
13 | public double phi;
14 |
15 | // protected boolean useRoundTrigonometry = false;
16 | public Projection3D(AWTDrawer _draw) {
17 | super(_draw);
18 | theta(Math.PI / 4);
19 | phi(Math.PI / 4);
20 | initBaseCoordsProjection(true);
21 | }
22 | public double factor = 1.4;
23 | public double x0, y0, z0;
24 | public double cos_phi, sin_phi, tan_phi, cos_theta, sin_theta, tan_theta;
25 | static double pi = Math.PI;
26 |
27 | private void theta(double theta) {
28 | if (theta == this.theta) {
29 | //System.err.println("o");
30 | return;
31 | }
32 | this.theta = theta;
33 | cos_theta = cos(theta);
34 | sin_theta = sin(theta);
35 | tan_theta = tan(theta);
36 | }
37 |
38 | private void phi(double phi) {
39 | if (phi == this.phi) {
40 | //System.err.println(".");
41 | return;
42 | }
43 | this.phi = phi;
44 | cos_phi = cos(phi);
45 | sin_phi = sin(phi);
46 | tan_phi = tan(phi);
47 | }
48 |
49 | public void initBaseCoordsProjection(boolean reset) {
50 | if (reset) {
51 | x0 = (draw.canvas.base.roundXmax[0] + draw.canvas.base.roundXmin[0]) / 2;
52 | y0 = (draw.canvas.base.roundXmax[1] + draw.canvas.base.roundXmin[1]) / 2;
53 | z0 = (draw.canvas.base.roundXmax[2] + draw.canvas.base.roundXmin[2]) / 2;
54 | }
55 | super.initBaseCoordsProjection(reset);
56 | }
57 | // search for (x0,y0,z0) , matching center of the screen [.5,.5] and closest to the center (.5,.5,.5) of the plot
58 |
59 | protected void updateCoordsCenterScreen() {
60 | double dx0 = (draw.canvas.getWidth() * .5 - baseScreenCoords[0][0]) / (baseScreenCoords[1][0] - baseScreenCoords[0][0]);
61 | double dy0 = (draw.canvas.getWidth() * .5 - baseScreenCoords[0][0]) / (baseScreenCoords[2][0] - baseScreenCoords[0][0]);
62 |
63 | double dz0 = (draw.canvas.getHeight() * .5 - baseScreenCoords[0][1]) / (baseScreenCoords[3][1] - baseScreenCoords[0][1]);
64 | double dx, dy, dz = 0;
65 | if ((theta - pi / 4) % pi > pi / 2) {
66 | dx = (.5 * (sin_theta + cos_theta) - tan_theta * dy0) / (sin_theta * sin_theta + cos_theta);
67 | dy = tan_theta * dx + dy0;
68 | } else {
69 | dy = (.5 * (sin_theta + cos_theta) - cos_theta * dx0) / (cos_theta / tan_theta + sin_theta);
70 | dx = 1 / tan_theta * dy + dx0;
71 | }
72 | dz = dz0 + .5 * tan_phi;
73 |
74 | // uuuhhh :) I've always dreamed to speak perl...
75 | dx = (dx < 0 ? 0 : (dx > 1 ? 1 : dx));
76 | dy = (dy < 0 ? 0 : (dy > 1 ? 1 : dy));
77 | dz = (dz < 0 ? 0 : (dz > 1 ? 1 : dz));
78 |
79 | x0 = draw.canvas.base.roundXmin[0] + (draw.canvas.base.roundXmax[0] - draw.canvas.base.roundXmin[0]) * dx;
80 | y0 = draw.canvas.base.roundXmin[1] + (draw.canvas.base.roundXmax[1] - draw.canvas.base.roundXmin[1]) * dy;
81 | z0 = draw.canvas.base.roundXmin[2] + (draw.canvas.base.roundXmax[2] - draw.canvas.base.roundXmin[2]) * dz;
82 | //System.err.println("(x0,y0,z0) = " + x0 + " " + y0 + " " + z0);
83 | }
84 |
85 | protected double[] baseCoordsScreenProjectionRatio(double[] xyz) {
86 | double normdist_xyz_x0 = ((xyz[0] - x0) / (draw.canvas.base.roundXmax[0] - draw.canvas.base.roundXmin[0]));
87 | double normdist_xyz_y0 = ((xyz[1] - y0) / (draw.canvas.base.roundXmax[1] - draw.canvas.base.roundXmin[1]));
88 | double normdist_xyz_z0 = ((xyz[2] - z0) / (draw.canvas.base.roundXmax[2] - draw.canvas.base.roundXmin[2]));
89 |
90 | double[] sC = new double[2];
91 | sC[0] = (cos_theta * normdist_xyz_y0
92 | - sin_theta * normdist_xyz_x0)
93 | / factor;
94 | sC[1] = (cos_phi * normdist_xyz_z0
95 | - sin_phi * cos_theta * normdist_xyz_x0
96 | - sin_phi * sin_theta * normdist_xyz_y0)
97 | / factor;
98 | //System.out.println("Theta = " + theta + " Phi = " + phi);
99 | // System.err.println("(" + xyz[0] +"," + xyz[1] +"," + xyz[2] + ") -> (" + sC[0] + "," + sC[1] + ")");
100 | return sC;
101 | }
102 |
103 | // TODO test efficiceny of an approximation of cos and sin fuctions.
104 | /*
105 | * private final static double _2PI = 2 * Math.PI;
106 | *
107 | * private final static int N = 100;
108 | *
109 | * private final static double[] COS =
110 | * DoubleArray.f(DoubleArray.increment(N, 0, 2 * Math.PI / (N - 1)), new
111 | * Function() { public double f(double x) { return Math.cos(x); } });
112 | *
113 | * private final static double[] SIN =
114 | * DoubleArray.f(DoubleArray.increment(N, 0, 2 * Math.PI / (N - 1)), new
115 | * Function() { public double f(double x) { return Math.sin(x); } });
116 | */
117 | private double cos(double x) {
118 | return FastMath.cos(x);
119 | }
120 |
121 | private double tan(double x) {
122 | return FastMath.tan(x);
123 | }
124 |
125 | private double sin(double x) {
126 | return FastMath.sin(x);
127 | }
128 |
129 | public void rotate(double _theta, double _phi) {
130 | theta(_theta);
131 | phi(_phi);
132 | initBaseCoordsProjection(false);
133 | }
134 |
135 | public void rotate(int[] screenTranslation, int[] dimension) {
136 | theta(theta - ((double) screenTranslation[0]) / 100);
137 | phi(phi + ((double) screenTranslation[1]) / 100);
138 | initBaseCoordsProjection(false);
139 | }
140 | }
--------------------------------------------------------------------------------
/src/main/java/org/math/plot/utils/Histogram.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Created on 21 juil. 2005 by richet
3 | */
4 | package org.math.plot.utils;
5 |
6 | import static org.math.plot.utils.Array.*;
7 |
8 | public class Histogram {
9 | // histograms functions
10 |
11 | public static double[][] histogram_classes(double[] values, double[] bounds) {
12 | return mergeColumns(centers(bounds), histogram(values, bounds));
13 | }
14 |
15 | public static double[][] histogram_classes(double[] values, double min, double max, int n) {
16 | double[] bounds = bounds(values, min, max, n);
17 | return mergeColumns(centers(bounds), histogram(values, bounds));
18 | }
19 |
20 | public static double[][] histogram_classes(double[] values, int n) {
21 | double[] bounds = bounds(values, n);
22 | return mergeColumns(centers(bounds), histogram(values, bounds));
23 | }
24 |
25 | public static double[] histogram(double[] values, double[] bounds) {
26 | double[] h = new double[bounds.length - 1];
27 | for (int i = 0; i < values.length; i++) {
28 | for (int j = 0; j < h.length; j++) {
29 | if (((bounds[j + 1] - values[i]) * (bounds[j] - values[i]) <= 0) || ((bounds[j] == values[i]))) {
30 | h[j]++;
31 | break;
32 | }
33 | }
34 | }
35 | return h;
36 | }
37 |
38 | public static double[] histogram(double[] values, double min, double max, int n) {
39 | double[] bounds = bounds(values, min, max, n);
40 | return histogram(values, bounds);
41 | }
42 |
43 | public static double[] histogram(double[] values, int n) {
44 | return histogram(values, n);
45 | }
46 |
47 | private static double[] bounds(double[] values, int n) {
48 | double min = min(values);
49 | double max = max(values);
50 | return bounds(values, min, max, n);
51 | }
52 |
53 | private static double[] bounds(double[] values, double min, double max, int n) {
54 | double[] bounds = new double[n + 1];
55 | for (int i = 0; i < bounds.length; i++) {
56 | bounds[i] = min + (max - min) * i / (double) n;
57 | }
58 | return bounds;
59 | }
60 |
61 | private static double[] centers(double[] bounds) {
62 | double[] center = new double[bounds.length - 1];
63 | for (int i = 0; i < center.length; i++)
64 | center[i] = (bounds[i] + bounds[i + 1]) / 2;
65 | return center;
66 | }
67 |
68 | // histograms 2D functions
69 |
70 | public static double[][] histogram_classes_2D(double[][] values, double[] boundsX, double[] boundsY) {
71 | return insertColumn(centers_2D(boundsX, boundsY), histogram_2D(values, boundsX, boundsY), 2);
72 | }
73 |
74 | public static double[][] histogram_classes_2D(double[][] values, double minX, double maxX, int nX, double minY, double maxY, int nY) {
75 | double[] valuesX = getColumnCopy(values, 0);
76 | double[] valuesY = getColumnCopy(values, 1);
77 | double[] boundsX = bounds(valuesX, minX, maxX, nX);
78 | double[] boundsY = bounds(valuesY, minY, maxY, nY);
79 | return insertColumn(centers_2D(boundsX, boundsY), histogram_2D(values, boundsX, boundsY), 2);
80 | }
81 |
82 | public static double[][] histogram_classes_2D(double[][] values, int nX, int nY) {
83 | double[] valuesX = getColumnCopy(values, 0);
84 | double[] valuesY = getColumnCopy(values, 1);
85 | double[] boundsX = bounds(valuesX, nX);
86 | double[] boundsY = bounds(valuesY, nY);
87 | return insertColumn(centers_2D(boundsX, boundsY), histogram_2D(values, boundsX, boundsY), 2);
88 | }
89 |
90 | public static double[] histogram_2D(double[][] values, double[] boundsX, double[] boundsY) {
91 | double[] h = new double[(boundsX.length - 1) * (boundsY.length - 1)];
92 | for (int n = 0; n < values.length; n++) {
93 | for (int i = 0; i < boundsX.length - 1; i++) {
94 | for (int j = 0; j < boundsY.length - 1; j++) {
95 | if ((((boundsX[i + 1] - values[n][0]) * (boundsX[i] - values[n][0]) < 0) || ((boundsX[i] == values[n][0])))
96 | && (((boundsY[j + 1] - values[n][1]) * (boundsY[j] - values[n][1]) < 0) || ((boundsY[j] == values[n][1]))))
97 | h[index2(i, j, boundsX.length - 1)]++;
98 | }
99 | }
100 | }
101 | return h;
102 | }
103 |
104 | public static double[] histogram_2D(double[][] values, double minX, double maxX, int nX, double minY, double maxY, int nY) {
105 | double[] valuesX = getColumnCopy(values, 0);
106 | double[] valuesY = getColumnCopy(values, 1);
107 | double[] boundsX = bounds(valuesX, minX, maxX, nX);
108 | double[] boundsY = bounds(valuesY, minY, maxY, nY);
109 | return histogram_2D(values, boundsX, boundsY);
110 | }
111 |
112 | public static double[] histogram_2D(double[][] values, int nX, int nY) {
113 | double[] valuesX = getColumnCopy(values, 0);
114 | double[] valuesY = getColumnCopy(values, 1);
115 | double[] boundsX = bounds(valuesX, nX);
116 | double[] boundsY = bounds(valuesY, nY);
117 | return histogram_2D(values, boundsX, boundsY);
118 | }
119 |
120 | private static double[][] centers_2D(double[] boundsX, double[] boundsY) {
121 | int nb_centers = (boundsX.length - 1) * (boundsY.length - 1);
122 | double[][] center = new double[nb_centers][2];
123 | for (int i = 0; i < boundsX.length - 1; i++) {
124 | for (int j = 0; j < boundsY.length - 1; j++) {
125 | int k = index2(i, j, boundsX.length - 1);
126 | center[k][0] = (boundsX[i] + boundsX[i + 1]) / 2;
127 | center[k][1] = (boundsY[j] + boundsY[j + 1]) / 2;
128 | }
129 | }
130 | return center;
131 | }
132 |
133 | private static int index2(int i, int j, int imax) {
134 | return i + imax * j;
135 | }
136 |
137 | // histograms 3D functions
138 |
139 |
140 |
141 |
142 | public static double[][] histogram_classes_3D(double[][] values, int nX, int nY, int nZ) {
143 | double[] valuesX = getColumnCopy(values, 0);
144 | double[] valuesY = getColumnCopy(values, 1);
145 | double[] valuesZ = getColumnCopy(values, 2);
146 | double[] boundsX = bounds(valuesX, nX);
147 | double[] boundsY = bounds(valuesY, nY);
148 | double[] boundsZ = bounds(valuesZ, nZ);
149 | return insertColumn(centers_3D(boundsX, boundsY, boundsZ), histogram_3D(values, boundsX, boundsY, boundsZ), 3);
150 | }
151 |
152 | public static double[] histogram_3D(double[][] values, double[] boundsX, double[] boundsY, double[] boundsZ) {
153 | double[] h = new double[(boundsX.length - 1) * (boundsY.length - 1)* (boundsZ.length - 1)];
154 | for (int n = 0; n < values.length; n++) {
155 | for (int i = 0; i < boundsX.length - 1; i++) {
156 | for (int j = 0; j < boundsY.length - 1; j++) {
157 | for (int k = 0; k < boundsZ.length - 1; k++) {
158 | if ((((boundsX[i + 1] - values[n][0]) * (boundsX[i] - values[n][0]) < 0) || ((boundsX[i] == values[n][0])))
159 | && (((boundsY[j + 1] - values[n][1]) * (boundsY[j] - values[n][1]) < 0) || ((boundsY[j] == values[n][1])))&& (((boundsZ[k + 1] - values[n][2]) * (boundsZ[k] - values[n][2]) < 0) || ((boundsZ[k] == values[n][2]))))
160 | h[index3(i, j,k, boundsX.length - 1, boundsY.length - 1)]++;
161 | }}
162 | }
163 | }
164 | return h;
165 | }
166 |
167 |
168 |
169 | private static double[][] centers_3D(double[] boundsX, double[] boundsY, double[] boundsZ) {
170 | int nb_centers = (boundsX.length - 1) * (boundsY.length - 1)* (boundsZ.length - 1);
171 | double[][] center = new double[nb_centers][3];
172 | for (int i = 0; i < boundsX.length - 1; i++) {
173 | for (int j = 0; j < boundsY.length - 1; j++) {
174 | for (int k = 0; k < boundsZ.length - 1; k++) {
175 | int l = index3(i, j,k, boundsX.length - 1, boundsY.length - 1);
176 | center[l][0] = (boundsX[i] + boundsX[i + 1]) / 2;
177 | center[l][1] = (boundsY[j] + boundsY[j + 1]) / 2;
178 | center[l][2] = (boundsZ[k] + boundsZ[k + 1]) / 2;
179 | }
180 | }
181 | }
182 | return center;
183 | }
184 |
185 |
186 |
187 |
188 | private static int index3(int i, int j, int k,int imax, int jmax) {
189 | return i + imax * j + imax*jmax*k;
190 | }
191 |
192 | }
193 |
--------------------------------------------------------------------------------
/src/main/resources/org/math/plot/icons/adjustbounds.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yannrichet/jmathplot/2938687e601c7f6782e8200ea991c6f160c13917/src/main/resources/org/math/plot/icons/adjustbounds.png
--------------------------------------------------------------------------------
/src/main/resources/org/math/plot/icons/back.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yannrichet/jmathplot/2938687e601c7f6782e8200ea991c6f160c13917/src/main/resources/org/math/plot/icons/back.png
--------------------------------------------------------------------------------
/src/main/resources/org/math/plot/icons/center.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yannrichet/jmathplot/2938687e601c7f6782e8200ea991c6f160c13917/src/main/resources/org/math/plot/icons/center.png
--------------------------------------------------------------------------------
/src/main/resources/org/math/plot/icons/data.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yannrichet/jmathplot/2938687e601c7f6782e8200ea991c6f160c13917/src/main/resources/org/math/plot/icons/data.png
--------------------------------------------------------------------------------
/src/main/resources/org/math/plot/icons/edit.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yannrichet/jmathplot/2938687e601c7f6782e8200ea991c6f160c13917/src/main/resources/org/math/plot/icons/edit.png
--------------------------------------------------------------------------------
/src/main/resources/org/math/plot/icons/noadjustbounds.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yannrichet/jmathplot/2938687e601c7f6782e8200ea991c6f160c13917/src/main/resources/org/math/plot/icons/noadjustbounds.png
--------------------------------------------------------------------------------
/src/main/resources/org/math/plot/icons/position.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yannrichet/jmathplot/2938687e601c7f6782e8200ea991c6f160c13917/src/main/resources/org/math/plot/icons/position.png
--------------------------------------------------------------------------------
/src/main/resources/org/math/plot/icons/rotation.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yannrichet/jmathplot/2938687e601c7f6782e8200ea991c6f160c13917/src/main/resources/org/math/plot/icons/rotation.png
--------------------------------------------------------------------------------
/src/main/resources/org/math/plot/icons/scale.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yannrichet/jmathplot/2938687e601c7f6782e8200ea991c6f160c13917/src/main/resources/org/math/plot/icons/scale.png
--------------------------------------------------------------------------------
/src/main/resources/org/math/plot/icons/toclipboard.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yannrichet/jmathplot/2938687e601c7f6782e8200ea991c6f160c13917/src/main/resources/org/math/plot/icons/toclipboard.png
--------------------------------------------------------------------------------
/src/main/resources/org/math/plot/icons/tofile.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yannrichet/jmathplot/2938687e601c7f6782e8200ea991c6f160c13917/src/main/resources/org/math/plot/icons/tofile.png
--------------------------------------------------------------------------------
/src/main/resources/org/math/plot/icons/topngfile.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yannrichet/jmathplot/2938687e601c7f6782e8200ea991c6f160c13917/src/main/resources/org/math/plot/icons/topngfile.png
--------------------------------------------------------------------------------
/src/main/resources/org/math/plot/icons/zoom.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yannrichet/jmathplot/2938687e601c7f6782e8200ea991c6f160c13917/src/main/resources/org/math/plot/icons/zoom.png
--------------------------------------------------------------------------------
/src/test/resources/TestApplet.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | 7 | 9 |
10 | 11 | --------------------------------------------------------------------------------