diff --git a/pub/plot/axis.cpp b/pub/plot/axis.cpp
index 4ebe1d6f6bff118432ec2cd5db8ee441b4e21abc..01a50438a7f894c204bbd94d4f634c87480eb7c1 100644
--- a/pub/plot/axis.cpp
+++ b/pub/plot/axis.cpp
@@ -362,10 +362,21 @@ void CAxis::calc_lintacks(vector<double>& Tacks, int& ntpt, double& dtack) const
         dtack = .25 * pow(10., ir);
         ntpt = 5;
     }
+    // Sets tack vector, taking extra precaution to avoid rounding errors.
     Tacks.clear();
-    for (double d = dtack * (floor(inf/dtack)-1); d <= dtack * (ceil(sup/dtack)+1); d += dtack)
+    double dlow = dtack * (floor(inf/dtack)-1);
+    double dhig = dtack * (ceil(sup/dtack)+1);
+    double drange = dhig-dlow;
+    int nTacks = drange/dtack + 1.5;
+    if (nTacks<2)
+        throw "BUG: calc_lintacks -> nTacks<2";
+    for (int i=0; i<nTacks; ++i) {
+        double d = (i*dhig + (nTacks-1-i)*dlow)/(nTacks-1);
+        if (std::abs(d)<1e-15*drange)
+            d = 0;
         if (inf-1e-4*range <= d && d <= sup+1e-4*range)
             Tacks.push_back(d);
+    }
 }