Repository: marcharper/python-ternary

Issue:
Planar to coordinates
Hello!

How to convert coordinates from planar simplex to maps (x,y,z) ternary? 

Comments:

Patch:
diff --git a/ternary/helpers.py b/ternary/helpers.py
index a72cbb9..06c4ae7 100644
--- a/ternary/helpers.py
+++ b/ternary/helpers.py
@@ -103,6 +103,26 @@ def project_point(p, permutation=None):
     return numpy.array([x, y])
 
 
+def planar_to_coordinates(p,scale):
+    """
+    Planar simplex (regular x,y) to maps (x,y,z) ternary coordinates. The order of the coordinates is counterclockwise from the origin.
+
+    Parameters
+    ----------
+    p: 2-tuple
+        The planar simplex (x, y) point to be transformed to maps (x,y,z) coordinates
+    
+    scale: Int
+        The normalized scale of the simplex, i.e. N such that points (x,y,z)
+        satisify x + y + z == N
+
+    """
+    x = p[0] - y/2
+    y = p[1] /  SQRT3OVER2
+    z = scale - (x + y)
+    return numpy.array([x, y, z])
+    
+    
 def project_sequence(s, permutation=None):
     """
     Projects a point or sequence of points using `project_point` to lists xs, ys
diff --git a/ternary/ternary_axes_subplot.py b/ternary/ternary_axes_subplot.py
index 85a8ecf..629a223 100644
--- a/ternary/ternary_axes_subplot.py
+++ b/ternary/ternary_axes_subplot.py
@@ -441,7 +441,7 @@ class TernaryAxesSubplot(object):
                             cb_kwargs=cb_kwargs)
 
     def heatmapf(self, func, scale=None, cmap=None, boundary=True,
-                 style='triangular', colorbar=True, scientific=True,
+                 style='triangular', colorbar=True, scientific=False,
                  vmin=None, vmax=None, cbarlabel=None, cb_kwargs=None):
         if not scale:
             scale = self.get_scale()


Test patch:
diff --git a/tests/test_helpers.py b/tests/test_helpers.py
index 2fe9640..4353c2b 100644
--- a/tests/test_helpers.py
+++ b/tests/test_helpers.py
@@ -3,7 +3,7 @@ import unittest
 
 from numpy.testing import assert_array_equal
 
-from ternary.helpers import normalize, project_point, simplex_iterator, SQRT3OVER2
+from ternary.helpers import normalize, project_point, planar_to_coordinates, simplex_iterator, SQRT3OVER2
 
 
 class FunctionCases(unittest.TestCase):
@@ -84,6 +84,32 @@ class FunctionCases(unittest.TestCase):
         expected = (1.5, SQRT3OVER2)
         assert_array_equal(projected, expected)
 
+    def test_planar_to_coordinates(self):
+        projected = (0.0, 0.0)
+        point = planar_to_coordinates(projected, scale = 100)
+        expected = (0.0, 0.0, 100.0)
+        assert_array_equal(point, expected)
+
+        projected = (100.0, 0.0)
+        point = planar_to_coordinates(projected, scale = 100)
+        expected = (100.0, 0.0, 0.0)
+        assert_array_equal(point, expected)
+
+        projected = (40.0,0)
+        point = planar_to_coordinates(projected, scale = 100)
+        expected = (40.0,  0.0 , 60.0)
+        assert_array_equal(point, expected)
+
+        projected = (10.0, SQRT3OVER2)
+        point = planar_to_coordinates(projected, scale = 100)
+        expected = (9.5,  1.0 , 89.5)
+        assert_array_equal(point, expected)
+
+        projected = (10.0, SQRT3OVER2)
+        point = planar_to_coordinates(projected, scale = 100)
+        expected = (9.5,  1.0 , 89.5)
+        assert_array_equal(point, expected)
+
 
 if __name__ == "__main__":
     unittest.main()