/
delay.py
165 lines (136 loc) · 5.17 KB
/
delay.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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
"""Delay space."""
# --- import --------------------------------------------------------------------------------------
import matplotlib.pyplot as plt
# --- label sectors -------------------------------------------------------------------------------
def label_sectors(
*,
labels=["I", "II", "IV", "VI", "V", "III"],
ax=None,
lw=2,
lc="k",
cs=None,
c_zlevel=2,
c_alpha=0.5,
fontsize=40
):
"""Label the six time-orderings in a three-pulse experiment.
Parameters
----------
labels : list of strings
Labels to place within sectors, starting in the upper left and
proceeding clockwise. Default is ['I', 'II', 'IV', 'VI', 'V', 'III'].
ax : matplotlib axis object (optional)
Axis to label. If None, uses current axis. Default is None.
cs : list of matplotlib colors (optional)
Color to label sectors. If None, sectors are not colored. Default is
None.
c_zlevel : number (optional)
Matplotlib zlevel of color. Default is 2.
c_alpha : number between 0 and 1.
Transparency of color. Default is 0.5
"""
if ax is None:
ax = plt.gca()
# label
factors = [
[0.25, 0.75],
[2 / 3, 5 / 6],
[5 / 6, 2 / 3],
[0.75, 0.25],
[1 / 3, 1 / 6],
[1 / 6, 1 / 3],
]
transform = ax.transAxes
for label, factor in zip(labels, factors):
ax.text(
*factor + [label], fontsize=fontsize, va="center", ha="center", transform=transform
)
# lines
if lw > 0:
ax.axhline(0, c=lc, lw=lw)
ax.axvline(0, c=lc, lw=lw)
ax.plot([0, 1], [0, 1], c=lc, lw=lw, transform=transform)
# colors
if cs is None:
cs = ["none"] * 6
xbound = ax.get_xbound()
ybound = ax.get_ybound()
factors = []
factors.append([[xbound[0], 0], [0, 0], [ybound[1], ybound[1]]])
factors.append([[0, xbound[1]], [0, ybound[1]], [ybound[1], ybound[1]]])
factors.append([[0, xbound[1]], [0, 0], [0, ybound[1]]])
factors.append([[0, xbound[1]], [ybound[0], ybound[0]], [0, 0]])
factors.append([[xbound[0], 0], [ybound[0], ybound[0]], [ybound[0], 0]])
factors.append([[xbound[0], 0], [ybound[0], 0], [0, 0]])
for color, factor in zip(cs, factors):
poly = ax.fill_between(*factor, facecolor=color, edgecolor="none", alpha=c_alpha)
poly.set_zorder(c_zlevel)
# --- testing -------------------------------------------------------------------------------------
if __name__ == "__main__":
plt.close()
fig = plt.figure()
ax = fig.add_subplot(111)
ax.plot([-1, 1], [-1, 1], color="k", linewidth=2)
ax.axhline(0, color="k", linewidth=2)
ax.axvline(0, color="k", linewidth=2)
ax.text(-0.5, 0.5, "I", fontsize=30, verticalalignment="center", horizontalalignment="center")
ax.text(0.25, 0.6, "II", fontsize=30, verticalalignment="center", horizontalalignment="center")
ax.text(
-0.6, -0.25, "III", fontsize=30, verticalalignment="center", horizontalalignment="center"
)
ax.text(0.6, 0.25, "IV", fontsize=30, verticalalignment="center", horizontalalignment="center")
ax.text(
-0.25, -0.6, "V", fontsize=30, verticalalignment="center", horizontalalignment="center"
)
ax.text(0.5, -0.5, "VI", fontsize=30, verticalalignment="center", horizontalalignment="center")
ax.set_xlabel(r"d1 $\mathrm{(\tau_{22^{\prime}})}$", fontsize=15)
ax.set_ylabel(r"d2 $\mathrm{(\tau_{21})}$", fontsize=15)
ax.set_title("ultimate representation")
ax.tick_params(
axis="both",
which="both",
bottom="off",
top="off",
left="off",
right="off",
labelleft="off",
labelbottom="off",
)
ax.set_aspect(1.)
plt.savefig("TRIEE_delay_space.png", transparent=True)
plt.close()
# as collected --------------------------------------------------------------------------------
fig = plt.figure()
ax = fig.add_subplot(111)
ax.plot([-1, 1], [1, -1], color="k", linewidth=2)
ax.axhline(0, color="k", linewidth=2)
ax.axvline(0, color="k", linewidth=2)
ax.text(0.5, 0.5, "I", fontsize=30, verticalalignment="center", horizontalalignment="center")
ax.text(
-0.25, 0.6, "II", fontsize=30, verticalalignment="center", horizontalalignment="center"
)
ax.text(
0.6, -0.25, "III", fontsize=30, verticalalignment="center", horizontalalignment="center"
)
ax.text(
-0.6, 0.25, "IV", fontsize=30, verticalalignment="center", horizontalalignment="center"
)
ax.text(0.25, -0.6, "V", fontsize=30, verticalalignment="center", horizontalalignment="center")
ax.text(
-0.5, -0.5, "VI", fontsize=30, verticalalignment="center", horizontalalignment="center"
)
ax.set_xlabel(r"d1 $\mathrm{(\tau_{2^{\prime}2})}$", fontsize=15)
ax.set_ylabel(r"d2 $\mathrm{(\tau_{21})}$", fontsize=15)
ax.set_title("as collected")
ax.tick_params(
axis="both",
which="both",
bottom="off",
top="off",
left="off",
right="off",
labelleft="off",
labelbottom="off",
)
ax.set_aspect(1.)
plt.savefig("TRIEE_delay_space_as_collected.png", transparent=True)