forked from marcharper/python-ternary
-
Notifications
You must be signed in to change notification settings - Fork 0
/
examples.py
142 lines (120 loc) · 4.7 KB
/
examples.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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
import os
import random
from matplotlib import pyplot as plt
import ternary
def load_sample_trajectory_data(filename="curve.txt", directory="sample_data"):
full_filename = os.path.join(directory, filename)
points = []
with open(full_filename) as handle:
for line in handle:
points.append(list(map(float, line.split(' '))))
return points
def random_points(num_points=25, scale=40):
points = []
for _ in range(num_points):
x = random.randint(1, scale)
y = random.randint(0, scale - x)
z = scale - x - y
points.append((x, y, z))
return points
if __name__ == '__main__':
# Show Coordinates
scale = 3
fig, tax = ternary.figure(scale=scale, permutation="120")
points_lists = [[(0, 0, 3), (1, 0, 2), (2, 0, 1)],
[(3, 0, 0), (2, 1, 0), (1, 2, 0)],
[(0, 3, 0), (0, 2, 1), (0, 1, 2)],
[(1, 1, 1)]]
colors = ['b', 'r', 'g', 'black']
markers = ['o', 'v', '*', 'd']
for i, points in enumerate(points_lists):
for point in points:
tax.scatter([tuple(point)], color=colors[i], marker=markers[i])
tax.annotate("".join(map(str, point)), tuple(point), color=colors[i])
tax.gridlines(multiple=1.)
## Boundary and Gridlines
scale = 40
fig, tax = ternary.figure(scale=scale)
left_kwargs = {'color': 'blue'}
right_kwargs = {'color': 'red'}
# Draw Boundary and Gridlines
tax.boundary(linewidth=2.0)
tax.gridlines(color="blue", multiple=5, left_kwargs=left_kwargs,
right_kwargs=right_kwargs)
# Draw Boundary and Gridlines
tax.boundary(linewidth=2.0)
tax.gridlines(color="black", multiple=5)
tax.gridlines(color="blue", multiple=1, linewidth=0.5)
# Set Axis labels and Title
fontsize = 20
tax.set_title("Simplex Boundary and Gridlines", fontsize=fontsize)
tax.left_axis_label("Left label $\\alpha^2$", fontsize=fontsize)
tax.right_axis_label("Right label $\\beta^2$", fontsize=fontsize)
tax.bottom_axis_label("Bottom label $\\Gamma - \\Omega$",
fontsize=fontsize)
tax.get_axes().axis('off')
tax.ticks(axis='lbr', clockwise=True, multiple=5, linewidth=1)
# Remove default Matplotlib Axes
tax.get_axes().axis('off')
tax.clear_matplotlib_ticks()
### Plot Various lines
scale = 40
fig, tax = ternary.figure(scale=scale)
# Draw Boundary and Gridlines
tax.boundary(linewidth=2.0)
tax.gridlines(color="blue", multiple=5)
# Set Axis labels and Title
fontsize = 20
tax.top_corner_label("X", fontsize=fontsize)
tax.left_corner_label("Y", fontsize=fontsize)
tax.right_corner_label("Z", fontsize=fontsize)
# Draw lines parallel to the axes
tax.horizontal_line(16)
tax.left_parallel_line(10, linewidth=2., color='red', linestyle="--")
tax.right_parallel_line(20, linewidth=3., color='blue')
# Draw an arbitrary line
p1 = (12, 8, 10)
p2 = (2, 26, 2)
tax.line(p1, p2, linewidth=3., marker='s', color='green', linestyle=":")
tax.get_axes().axis('off')
tax.clear_matplotlib_ticks()
tax.ticks(axis='lbr', multiple=5, linewidth=1)
### Scatter Plot
scale = 40
fig, tax= ternary.figure(scale=scale)
tax.set_title("Scatter Plot", fontsize=20)
tax.boundary(linewidth=2.0)
tax.gridlines(multiple=5, color="blue")
# Plot a few different styles with a legend
points = random_points(30, scale=scale)
tax.scatter(points, marker='s', color='red', label="Red Squares")
points = random_points(30, scale=scale)
tax.scatter(points, marker='D', color='green', label="Green Diamonds")
tax.legend()
tax.ticks(axis='lbr', multiple=5, linewidth=1)
tax.get_axes().axis('off')
tax.clear_matplotlib_ticks()
## Sample trajectory plot
fig, tax = ternary.figure(scale=1.0)
tax.boundary()
tax.set_title("Plotting of sample trajectory data", fontsize=20)
points = load_sample_trajectory_data()
tax.gridlines(multiple=0.2, color="black")
tax.plot(points, linewidth=2.0, label="Curve")
tax.legend()
tax.get_axes().axis('off')
tax.clear_matplotlib_ticks()
## Sample colored trajectory plot
fig, tax = ternary.figure(scale=1.0)
tax.boundary()
tax.set_title("Plotting of sample trajectory data", fontsize=20)
points = load_sample_trajectory_data()
tax.gridlines(multiple=0.2, color="black")
tax.plot_colored_trajectory(points, linewidth=2.0)
points = [(y, z, x) for (x, y, z) in points]
tax.plot_colored_trajectory(points, cmap="hsv", linewidth=2.0)
tax.legend()
tax.get_axes().axis('off')
tax.clear_matplotlib_ticks()
tax.ticks(axis='lbr', linewidth=1, multiple=0.1)
plt.show()