NOTICE: This version of the NSF Unidata web site (archive.unidata.ucar.edu) is no longer being updated.
Current content can be found at unidata.ucar.edu.

To learn about what's going on, see About the Archive Site.

Re: scatter plot and mark each data point with a shape

Hi

I have composed a simple code (see below) to do 2D scatter, but I see no data
points on the screen marked by the defined shape square.  Can anyone tell me
what I did wrong in the folowing code?

Thanks a lot. /Helen
------------- code follows -------------

import visad.*;
import visad.java2d.DisplayImplJ2D;
import java.rmi.RemoteException;
import java.awt.*;
import javax.swing.*;

public class ScatterPlot2D {

  private RealType time, height, mark, scale, index;
  private RealTupleType t_h_tuple;
  private FunctionType func_i_tuple;
  private Set index_set;
  private FlatField vals_ff;

  private DataReferenceImpl data_ref;
  private DisplayImpl display;
  private ScalarMap timeMap, heightMap, markMap, scaleMap;


    /** Creates a new instance of ScatterPlot2D */
    public ScatterPlot2D() throws RemoteException, VisADException {

        time = RealType.getRealType("time");
        height = RealType.getRealType("height");
        mark = RealType.getRealType("mark");
        scale = RealType.getRealType("scale");

        t_h_tuple = new RealTupleType( time, height, mark, scale);

        index = RealType.getRealType("index");

        func_i_tuple = new FunctionType( index, t_h_tuple);

        index_set = new Integer1DSet(index, 5);


        display = new DisplayImplJ2D("display1");

        GraphicsModeControl dispGMC = (GraphicsModeControl)
display.getGraphicsModeControl();
        dispGMC.setScaleEnable(true);

        timeMap = new ScalarMap( time, Display.XAxis );
        heightMap = new ScalarMap( height, Display.YAxis );
        markMap = new ScalarMap(mark, Display.Shape);
        scaleMap = new ScalarMap(scale, Display.ShapeScale);

        timeMap.setRange( -4.0, 4.0);
        heightMap.setRange( -10.0, 50.0);
        scaleMap.setRange(0.01, 10.0);

        // Add maps to display

        display.addMap( timeMap );
        display.addMap( heightMap );

        display.addMap( markMap );
        display.addMap( scaleMap );

        VisADQuadArray square = new VisADQuadArray();
        square.coordinates = new float[]
        {0.1f,  0.1f, 0.0f,     0.1f, -0.1f, 0.0f,
        -0.1f, -0.1f, 0.0f,    -0.1f,  0.1f, 0.0f};
        square.vertexCount = square.coordinates.length / 3;

        float[][] counts = {{0.0f,1.0f,2.0f, 3.0f,4.0f}};
        Gridded1DSet count_set = new Gridded1DSet(mark, counts,
counts[0].length);

        VisADGeometryArray[] shapes = {square,square,square,square,square};
        ShapeControl shape_control = (ShapeControl) markMap.getControl();
        shape_control.setShapes(shapes);
        shape_control.setShapeSet(count_set);

        float[][] point_vals = new float[][]{{-3.0f, -1.5f, 0.0f, 1.5f,
3.0f,},
              {0.0f, 33.75f, 45.0f, 33.75f, 0.0f,},
                                             {0.0f,  1.0f,  2.0f,  3.0f,
4.0f,},
                                             {1.0f,  2.0f,  3.0f,  4.0f,
5.0f,}};

        vals_ff = new FlatField( func_i_tuple, index_set);

        vals_ff.setSamples( point_vals );

        // Create a data reference and set the FlatField as our data

        data_ref = new DataReferenceImpl("data_ref");

        data_ref.setData( vals_ff );

        display.addReference( data_ref);

       // Create application window, put display into it

    JFrame jframe = new JFrame("VisAD Tutorial example 2_03");
    jframe.getContentPane().add(display.getComponent());

    // Set window size and make it visible

    jframe.setSize(300, 300);
    jframe.setVisible(true);

    }

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) throws RemoteException,
VisADException {
        new ScatterPlot2D();
    }

}




Bill Hibbard wrote:

> Hi Helen,
>
> > I like to draw a 2D scatter plot. Following the example P2_04 in
> > tutorial, it is easy to create a 2D scatter plot with certain size
> > points. But how can I change those points to the  shapes, such as filled
> > triangle or dimond, with changable ShapeScale?
>
> P2_04 has a Field with MathType ( index -> (time, height) ) and
> ScalarMaps time -> XAxis and height -> YAxis. To use Shape you
> can add ScalarMaps of time or height to Shape and ShapeScale, or
> better yet use shapes to add some new information. For this,
> expand your Field to include other variables, such as:
>
>   ( index -> (time, height, u, v) )
>
> and Display with ScalarMaps:
>
>   time -> XAxis
>   height -> YAxis
>   u -> Shape
>   v -> ShapeScale
>
> See Test46.java and Test47.java in visad/examples for examples
> of how to use Shape and ShapeScale.
>
> Good luck,
> Bill


  • 2003 messages navigation, sorted by:
    1. Thread
    2. Subject
    3. Author
    4. Date
    5. ↑ Table Of Contents
  • Search the visad archives: