octave-maintainers
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: help with graphics


From: John W. Eaton
Subject: Re: help with graphics
Date: Wed, 26 Oct 2011 03:15:32 -0400

On 26-Oct-2011, Michael Goffioul wrote:

| On Wed, Oct 26, 2011 at 8:00 AM, John W. Eaton <address@hidden> wrote:
| > On 26-Oct-2011, Michael Goffioul wrote:
| >
| > | Do you mean you don't see anything in the plot, even the axes box?
| >
| > Right, the plot window is blank.  No axes box or lines.
| 
| The transformation is probably wrong. Have a look at the scaler
| object, I think that's the best way to handle the problem.

OK, just this simple change fixes a lot of the trouble, but not
everything (this is just a quick fix to test the idea; I'll look at
doing something better later):

diff --git a/src/graphics.cc b/src/graphics.cc
--- a/src/graphics.cc
+++ b/src/graphics.cc
@@ -5588,8 +5588,8 @@
           else
             {
               // Log plots with all negative data
-              min_val = -pow (10, gnulib::floor (log10 (-min_val)));
-              max_val = -pow (10, std::ceil (log10 (-max_val)));
+              min_val = -pow (10, std::ceil (log10 (-min_val)));
+              max_val = -pow (10, gnulib::floor (log10 (-max_val)));
             }
         }
       else
diff --git a/src/graphics.h.in b/src/graphics.h.in
--- a/src/graphics.h.in
+++ b/src/graphics.h.in
@@ -212,6 +212,22 @@
   bool is_linear (void) const { return true; }
 };
 
+static bool
+all_negative (const MArray<double>& m)
+{
+  bool retval = true;
+  const double *data = m.data ();
+  for (octave_idx_type i = 0; i < m.numel (); i++)
+    {
+      if (data[i] >= 0)
+        {
+          retval = false;
+          break;
+        }
+    }
+  return retval;
+}
+
 class log_scaler : public base_scaler
 {
 public:
@@ -221,7 +237,10 @@
     {
       Matrix retval (m.rows (), m.cols ());
 
-      do_scale (m.data (), retval.fortran_vec (), m.numel ());
+      if (all_negative (m))
+        do_neg_scale (m.data (), retval.fortran_vec (), m.numel ());
+      else
+        do_scale (m.data (), retval.fortran_vec (), m.numel ());
       return retval;
     }
 
@@ -229,7 +248,10 @@
     {
       NDArray retval (m.dims ());
 
-      do_scale (m.data (), retval.fortran_vec (), m.numel ());
+      if (all_negative (m))
+        do_neg_scale (m.data (), retval.fortran_vec (), m.numel ());
+      else
+        do_scale (m.data (), retval.fortran_vec (), m.numel ());
       return retval;
     }
 
@@ -248,6 +270,11 @@
       for (int i = 0; i < n; i++)
         dest[i] = log10(src[i]);
     }
+  void do_neg_scale (const double *src, double *dest, int n) const
+    {
+      for (int i = 0; i < n; i++)
+        dest[i] = log10(-src[i]);
+    }
 };
 
 class scaler


The tick marks are displaced so that they are on top of the axis
lines.  Not sure yet why that is happening.  I'll take a look at it
later.  First I need to get some sleep...

Thanks!

jwe


reply via email to

[Prev in Thread] Current Thread [Next in Thread]