display points using log scale
Celine Gestas
celine.gestas at gmail.com
Mon Mar 26 13:58:22 MDT 2007
Actually it does autoscale but only for the line ... That is why I would
like to use point mode and the default mode both maybe extending the
GraphicsModeControl class...
2007/3/26, Don Murray <dmurray at unidata.ucar.edu>:
>
> Hi Celine-
>
> Attached is a program that lets the user switch between
> log and non-log Y axis. It's based on the LogTest file
> I sent you earlier off list. Note that as before you
> need to explicitly set the range for the logMap. I'm
> not sure why it doesn't autoscale.
>
> Hope it helps.
>
> Don
>
> Don Murray wrote:
> > Hi Celine-
> >
> > I'm travelling and don't have time to do this justice, but
> > here's my take on it. I have not been able to follow your
> > code in detail, but here's my take on it. You have some
> > X or Y values. You can use X or Y for those real types.
> > For the Log values, you can create a RealType (e.g. LogX,
> > LogY) which is used for the reference realtype of the
> > LogCoordinateSystem. VisAD automatically does the calculations
> > converting the values to the log values. What you have below
> > looks like you are trying to go the other way. Your Integer1DSet
> > has index as the reference of the CS so values of 0,1,2,3 will
> > get converted to the log of those values when index is mapped
> > to a scale. I would think you would want it the other way.
> >
> > Another question is are you removing the non-log scalar maps
> > when you switch to log displays and vice-versa?
> >
> > Again, I'm travelling so may not answer until I get back.
> >
> > Don
> >
> >
> > Celine Gestas wrote:
> >> Thank you for your answer but there is no change : points are
> >> displayed but
> >> not in the log scale, it keeps the default scale. What I changed is :
> >>
> >> index = RealType.getRealType("index",
> >> CommonUnit.promiscuous);
> >> indexLog = RealType.getRealType("indexLog",
> >> CommonUnit.promiscuous); // new RealType
> >> referenceIndex = new RealTupleType(index);
> >> LogCoordinateSystem logCSindex = new
> >> LogCoordinateSystem(referenceIndex, base);
> >> rangeIndex = new RealTupleType(indexLog,
> >> logCSindex,
> >> null); // use the new
> >> RealType
> >> index_set = new Integer1DSet(rangeIndex,
> >> x_vals[0].length, logCSindex, null, null);
> >>
> >> 2007/3/26, Bill Hibbard <hiding at japan.com>:
> >>>
> >>> Hi Celine,
> >>>
> >>> If someone has an idea ...
> >>>
> >>> RealTupleType rangeIndex = null;
> >>>
> >>> // create the index
> >>> if (log.equals("logX") || log.equals("logY")
> >>> ||log.equals("loglog")) {
> >>> index = RealType.getRealType("index",
> >>> CommonUnit.promiscuous);
> >>> RealTupleType referenceIndex = new RealTupleType(index);
> >>> LogCoordinateSystem logCSindex = new
> >>> LogCoordinateSystem(referenceIndex, base);
> >>> rangeIndex = new RealTupleType(index, logCSindex, null);
> >>> index_set = new Integer1DSet(rangeIndex, x_vals[0].length,
> >>> logCSindex, null, null);
> >>> }
> >>>
> >>> I think the problem is that the RealTupleTypes referenceIndex and
> >>> rangeIndex are both
> >>> defined as (index), that is they are both a RealTupleType of the same
> >>> single RealType.
> >>> This may also explain the very mysterious Exception you reported in
> your
> >>> other recent
> >>> message to the list. Try using different RealTypes in the
> >>> constructors for
> >>> referenceIndex
> >>> and rangeIndex.
> >>>
> >>> Good luck,
> >>> Bill
> >>>
> >>>
> >>> --
> >>>
> >>> <http://a8-asy.a8ww.net/a8-ads/adftrclick?redirectid=en-mail_a_01>
> >>>
> >>
> >
>
> --
> *************************************************************
> Don Murray UCAR Unidata Program
> dmurray at unidata.ucar.edu P.O. Box 3000
> (303) 497-8628 Boulder, CO 80307
> http://www.unidata.ucar.edu/staff/donm
> *************************************************************
>
>
> import visad.*;
> import javax.swing.*;
> import java.awt.*;
> import java.awt.event.*;
> import visad.java2d.*;
> import java.util.Hashtable;
>
> public class LogDisplay {
>
> public LogDisplay(double base)
> throws VisADException, java.rmi.RemoteException {
>
> // Set up the metadata
> // make a realtype for the values and for log values
> // create a CS that transforms from values to log values
> RealType values = RealType.getRealType("Values");
> RealType logValues
> RealType.getRealType("LogValues", CommonUnit.promiscuous);
> RealTupleType reference = new RealTupleType(logValues);
> CoordinateSystem logCS = new LogCoordinateSystem(reference, base);
> RealTupleType range = new RealTupleType(values, logCS, null);
>
> // Create realtype for domain
> RealType exponent = RealType.getRealType("Exponent");
> FunctionType fType = new FunctionType(exponent, range);
> Integer1DSet domain = new Integer1DSet(exponent, 4);
>
> // make a field to hold the data
> FlatField field = new FlatField(fType, domain);
> float[][] rangeValues = new float[][] { { 1, 10, 100, 1000 } };
> field.setSamples(rangeValues);
>
> // Create the display
> final DisplayImpl display = new DisplayImplJ2D("log display");
> display.getGraphicsModeControl().setScaleEnable(true);
> final ScalarMap yMap = new ScalarMap(values, Display.YAxis);
> final ScalarMap logMap = new ScalarMap(logValues, Display.YAxis);
> logMap.setRange(0,3);
> Hashtable logLabels = new Hashtable();
> logLabels.put(new Double(0), "1");
> logLabels.put(new Double(1), "10");
> logLabels.put(new Double(2), "100");
> logLabels.put(new Double(3), "1000");
> logMap.getAxisScale().setLabelTable(logLabels);
> logMap.getAxisScale().setMajorTickSpacing(1);
> logMap.getAxisScale().setTitle("Log Values");
> display.addMap(yMap);
> display.addMap(new ScalarMap(exponent, Display.XAxis));
> DataReference ref = new DataReferenceImpl("ref");
> ref.setData(field);
> display.addReference(ref);
>
> JFrame frame = new JFrame("Log Display");
> frame.addWindowListener(new WindowAdapter() {
> public void windowClosing(WindowEvent e) {
> System.exit(0);
> }
> });
> frame.getContentPane().add(display.getComponent());
> JPanel p = new JPanel();
> ButtonGroup b = new ButtonGroup();
> JRadioButton rb = new JRadioButton("Y",true);
> b.add(rb);
> rb.addActionListener(new ActionListener() {
> public void actionPerformed(ActionEvent e) {
> try {
> display.removeMap(logMap);
> display.addMap(yMap);
> } catch (Exception ve) { ve.printStackTrace(); }
>
> }
> });
> p.add(rb);
> rb = new JRadioButton("Log Y");
> b.add(rb);
> rb.addActionListener(new ActionListener() {
> public void actionPerformed(ActionEvent e) {
> try {
> display.removeMap(yMap);
> display.addMap(logMap);
> } catch (Exception ve) { ve.printStackTrace(); }
> }
> });
> p.add(rb);
> frame.getContentPane().add(p, BorderLayout.SOUTH);
>
> frame.pack();
> frame.setVisible(true);
> }
>
> public static void main(String[] args)
> throws Exception {
> double base = 10.0;
> if (args.length > 0) {
> try {
> base = Double.parseDouble(args[0]);
> }
> catch (Exception e) { base = 10.0; }
> }
> LogDisplay lt = new LogDisplay(base);
> }
>
> }
>
>
More information about the visad
mailing list