-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathternary_plot.py
80 lines (59 loc) · 1.97 KB
/
ternary_plot.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
import random
import ternary
import ternary.helpers
import matplotlib
matplotlib.rcParams['figure.dpi'] = 200
matplotlib.rcParams['figure.figsize'] = (4, 4)
def generate_random_heatmap_data(scale=5):
from ternary.helpers import simplex_iterator
d = dict()
for (i,j,k) in simplex_iterator(scale):
d[(i,j)] = random.random()
return d
scale = 20
d = generate_random_heatmap_data(scale)
figure, tax = ternary.figure(scale=scale)
figure.set_size_inches(10, 8)
tax.heatmap(d, style="h")
tax.boundary()
tax.clear_matplotlib_ticks()
tax.get_axes().axis('off')
tax.set_title("Heatmap Test: Hexagonal")
ternary.plt.show()
## Boundary and Gridlines
scale = 30
figure, tax = ternary.figure(scale=scale)
# Draw Boundary and Gridlines
tax.boundary(linewidth=1.5)
tax.gridlines(color="black", multiple=6)
tax.gridlines(color="blue", multiple=2, linewidth=0.5)
# Set Axis labels and Title
fontsize = 12
offset = 0.14
tax.set_title("Simplex Boundary and Gridlines\n", fontsize=fontsize)
tax.left_axis_label("Left label $\\alpha^2$", fontsize=fontsize, offset=offset)
tax.right_axis_label("Right label $\\beta^2$", fontsize=fontsize, offset=offset)
tax.bottom_axis_label("Bottom label $\\Gamma - \\Omega$", fontsize=fontsize, offset=offset)
def random_points(num_points=25, scale=40):
points = []
for i in range(num_points):
x = random.randint(1, scale)
y = random.randint(0, scale - x)
z = scale - x - y
points.append((x,y,z))
print((x,y,z))
return points
scale = 40
figure, tax = ternary.figure(scale=scale)
figure.set_size_inches(10, 10)
points = random_points(30, scale=scale)
tax.scatter(points, marker='s', color='red', label="Red Squares")
tax.legend()
# Set ticks
tax.ticks(axis='lbr', linewidth=1, multiple=5, offset=0.02)
# Background color
tax.set_background_color(color="whitesmoke", alpha=0.7) # the detault, essentially
# Remove default Matplotlib Axes
tax.clear_matplotlib_ticks()
tax.get_axes().axis('off')
ternary.plt.show()