diff --git a/README.md b/README.md
index 4db5e77..8add8a2 100644
--- a/README.md
+++ b/README.md
@@ -27,6 +27,7 @@ The library provides functions for plotting projected lines, curves (trajectorie
+
Last image from: Genetic Drift and Selection in Many-Allele Range Expansions.
@@ -172,6 +173,13 @@ The following code draws a boundary for the simplex and gridlines.
+## Order of coordinates
+
+Each position in the ternary plot can be represented by a three-tuple coordinate, the first element corresponds to the value of the ''right corner element'', the second to the ''top corner element'' and the third to the ''left corner element''. Plotting the function _f(p) = (p[0] - p[1])(1 - p[2])_ gives the resulting heatmap
+
+
+
+
## Drawing lines
You can draw individual lines between any two points with `line` and lines
@@ -292,7 +300,7 @@ Similarly, ternary can make scatter plots:
Ternary can plot heatmaps in two ways and three styles. Given a function, ternary
will evaluate the function at the specified number of steps (determined by the
-scale, expected to be an integer in this case). The simplex can be split up into
+scale, expected to be an integer in this case). Additional arguments can be passed to the function as an iterable throught the keyword argument 'fargs'. The simplex can be split up into
triangles or hexagons and colored according to one of three styles:
- Triangular -- `triangular` (default): coloring triangles by summing the values on the
@@ -394,6 +402,49 @@ do so automatically when you pass `clockwise=True` to `tax.ticks()`.
There is a [more detailed discussion](https://github.com/marcharper/python-ternary/issues/18)
on issue #18 (closed).
+Setting custom values corresponding to the max and min values of the axis, rather than the `scale` parameter can be done using a combination of `tax.get_ticks_from_axis_limits()` and `tax.set_custom_ticks()`.
+
+```python
+import ternary
+from matplotlib.cm import get_cmap
+import matplotlib.pyplot as plt
+
+cmap = get_cmap('bwr')
+
+def well_behaved_func(x):
+ return (x[0] - x[1]) * (1 - x[2])
+
+scale = 60
+
+fig, tax = ternary.figure(scale=scale)
+tax.set_axis_limits({'b' : [0,1], 'l' : [0, 1], 'r' : [0, 1]})
+tax.heatmapf(well_behaved_func, boundary=True,
+ style='triangular', cmap=cmap,
+ vmin=-1, vmax=1)
+
+
+offset = 0.14
+tax.boundary(linewidth=1.0)
+tax.top_corner_label('p[1]')
+tax.right_axis_label('p[1]', offset=offset)
+tax.right_corner_label('p[0]')
+tax.bottom_axis_label('p[0]', offset=offset)
+tax.left_corner_label('p[2]', offset=offset)
+tax.left_axis_label('p[2]', offset=offset)
+tax._redraw_labels()
+
+# This part fixes the custom ticks
+tax.get_ticks_from_axis_limits(multiple=11)
+tax.set_custom_ticks(tick_formats='%.1f', offset=0.025)
+tax.get_axes().axis('off')
+tax.clear_matplotlib_ticks()
+
+plt.savefig('meaningful_ticks')
+
+```
+
+
+
# RGBA colors
diff --git a/readme_images/argument_order.png b/readme_images/argument_order.png
new file mode 100644
index 0000000..f1cc15d
Binary files /dev/null and b/readme_images/argument_order.png differ
diff --git a/ternary/heatmapping.py b/ternary/heatmapping.py
index 7487f69..2e67ab2 100644
--- a/ternary/heatmapping.py
+++ b/ternary/heatmapping.py
@@ -270,7 +270,7 @@ def heatmap(data, scale, vmin=None, vmax=None, cmap=None, ax=None,
## User Convenience Functions ##
-def heatmapf(func, scale=10, boundary=True, cmap=None, ax=None,
+def heatmapf(func, scale=10, , fargs=None, boundary=True, cmap=None, ax=None,
scientific=False, style='triangular', colorbar=True,
permutation=None, vmin=None, vmax=None, cbarlabel=None,
cb_kwargs=None):
@@ -285,6 +285,8 @@ def heatmapf(func, scale=10, boundary=True, cmap=None, ax=None,
A function of 3-tuples to be heatmapped
scale: Integer
The scale used to partition the simplex
+ fargs: iterable
+ Additional arguments to pass to func
boundary: Bool, True
Include the boundary points or not
cmap: String, None
@@ -313,8 +315,12 @@ def heatmapf(func, scale=10, boundary=True, cmap=None, ax=None,
# Apply the function to a simplex partition
data = dict()
- for i, j, k in simplex_iterator(scale=scale, boundary=boundary):
- data[(i, j)] = func(normalize([i, j, k]))
+ if fargs is None:
+ for i, j, k in simplex_iterator(scale=scale, boundary=boundary):
+ data[(i, j)] = func(normalize([i, j, k]))
+ else:
+ for i, j, k in simplex_iterator(scale=scale, boundary=boundary):
+ data[(i, j)] = func(normalize([i, j, k]), fargs)
# Pass everything to the heatmapper
ax = heatmap(data, scale, cmap=cmap, ax=ax, style=style,
scientific=scientific, colorbar=colorbar,