Contour Plot, Explicación
Description
Primero se importan las clases necesarias
```
import org.opensourcephysics.display.DrawingFrame;
import org.opensourcephysics.display.DrawingPanel;
import org.opensourcephysics.display.PlottingPanel;
import org.opensourcephysics.display2d.ContourPlot;
```
La clase primero incluye la ceración del panel
```
DrawingPanel plottingPanel = new PlottingPanel("x", "y", "Contour Plot");
DrawingFrame frame = new DrawingFrame(plottingPanel);
```
Despeus se deben generar la matriz de datos
```
int SIZE = 100;
double[][] data = new double[SIZE][SIZE];
ContourPlot plot = new ContourPlot();
plot.setAll(data,-1.5,1.5,-1.5,1.5);
for(int i = 0;i < SIZE;i++) {
double x = plot.indexToX(i);
for(int j = 0;j < SIZE;j++){
double y = plot.indexToY(j);
data[i][j] = Math.exp(-(x*x+y*y));
}
}
plot.setAll(data);
plottingPanel.addDrawable(plot);
```
Finalmente carga al frame:
```
frame.setDefaultCloseOperation(javax.swing.JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
```
El código fuente del constructor se puede bajar de
[Contour.java](Contour.java)
ID:(7536, 0)
Contour Plot, Código
Description
![constructor](structure/lego-blue.jpg)
Código del constructor
```
import org.opensourcephysics.display.DrawingFrame;
import org.opensourcephysics.display.DrawingPanel;
import org.opensourcephysics.display.PlottingPanel;
import org.opensourcephysics.display2d.ContourPlot;
public class Contour {
Contour(){
DrawingPanel plottingPanel = new PlottingPanel("x", "y", "Contour Plot");
DrawingFrame frame = new DrawingFrame(plottingPanel);
int SIZE = 100;
double[][] data = new double[SIZE][SIZE];
ContourPlot plot = new ContourPlot();
plot.setAll(data,-1.5,1.5,-1.5,1.5);
for(int i = 0;i < SIZE;i++) {
double x = plot.indexToX(i);
for(int j = 0;j < SIZE;j++){
double y = plot.indexToY(j);
data[i][j] = Math.exp(-(x*x+y*y));
}
}
plot.setAll(data);
plottingPanel.addDrawable(plot);
frame.setDefaultCloseOperation(javax.swing.JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
}
}
```
ID:(7537, 0)