diff --git a/pub/src/axis.cpp b/pub/src/axis.cpp
index 8dc1dbbcf536d72290d874e266b5ee2f7ff95ed1..d3e06b72d037bf156a5b8765b90c17337d3f6ffa 100644
--- a/pub/src/axis.cpp
+++ b/pub/src/axis.cpp
@@ -192,21 +192,37 @@ bool CAxis::finite() const
 
 //! Is value val contained in this range?
 
-bool CAxis::contains(double val)  const
+bool CAxis::contains(double val) const
 {
     return inf<=val && val<=sup;
 }
 
 
+//! Do values v1 and v2 agree within tolerance tol, relative to axis span?
+
+bool CAxis::close_enough( double v1, double v2, double tol ) const
+{
+    if ( !finite() )
+        throw "undefined plot range";
+    if ( logflag ) {
+        if ( v1<=0 || v2<=0 )
+            return false;
+        return fabs(log(v1/v2)) <= tol*log(sup/inf);
+    } else {
+        return fabs(v1-v2) <= tol*(sup-inf);
+    }
+}
+
+
 //! Map application scale (inf..sup) to linear plot scale (0..1).
 
 double CAxis::value2plotcoord( double v ) const
 {
     if ( !finite() )
-        throw string( "undefined plot range" );
+        throw "undefined plot range";
     if ( logflag ) {
         if( inf<0 || v<0 )
-            throw string( "negative value in log range" );
+            throw "negative value in log range";
         return log(v/inf) / log(sup/inf);
     } else {
         return (v-inf) / (sup-inf);
diff --git a/pub/src/axis.h b/pub/src/axis.h
index dddfbf304889106916ffacf632bf9b5191ce425e..87f33f4f25d633666c905bc9b92a12cb8360bcc5 100644
--- a/pub/src/axis.h
+++ b/pub/src/axis.h
@@ -18,6 +18,7 @@ class CAxis {
     string info() const;
     bool finite() const;
     bool contains( double val ) const;
+    bool close_enough( double v1, double v2, double tol ) const;
     double value2plotcoord( double v ) const;
     double value2ploterror( double v, double dv ) const;
     void set_xgrid( vector<double>& x, int n ) const;
diff --git a/pub/src/plot.cpp b/pub/src/plot.cpp
index 8e21ea8f476e82c5ef48d427f5cec825e7e89e7d..6921ceda6f7eea9b14894d5d8d9df41352ea2c9d 100644
--- a/pub/src/plot.cpp
+++ b/pub/src/plot.cpp
@@ -278,7 +278,7 @@ void NPlot::Plot( class CPlot *plot, bool add )
                         vector<double> xa, ya;
                         uint ic=0, in=0;
                         for ( ; ic<xc.size() && in<xn.size(); ) {
-                            if ( fabs( xc[ic]-xn[ic] ) < 1e-7 ) {
+                            if ( plot->X.close_enough( xc[ic], xn[ic], 1e-7 ) ){
                                 ++in; // skip new point
                             } else if ( xc[ic]<xn[in] ) {
                                 xa.push_back( xc[ic] );
@@ -344,8 +344,7 @@ void NPlot::Plot( class CPlot *plot, bool add )
                             double yi = ( (xn[i+1]-xn[i])*yn[i-1] +
                                           (xn[i]-xn[i-1])*yn[i+1] ) /
                                 (xn[i+1]-xn[i-1]);
-                            if ( fabs( yn[i] - yi ) > 0.01*
-                                 (plot->Y.sup - plot->Y.inf) ) {
+                            if ( plot->Y.close_enough( yn[i], yi, 0.005 ) ) {
                                 xc.push_back( (xn[i-1] + xn[i])/2 );
                                 //cout << "DEB disc " << xc.back() << "\n";
                                 insert_next = true;