Skip to content

Commit 6646766

Browse files
committed
Support annotation.textcoords == "offset points"
This modifies `_annotation` to return the location at which the text should be rendered, and then adds support for `offset points` and `offset pixels`. This should make it easier to add support for the other coordinate type too, but I'll leave that for someone who needs them. This also fixes a bug where an arrow would be drawn even if none was requested. A test is added for this.
1 parent 647da40 commit 6646766

File tree

7 files changed

+143
-100
lines changed

7 files changed

+143
-100
lines changed

test/test_annotate.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,13 @@ def plot():
2626
textcoords="offset points",
2727
arrowprops=dict(arrowstyle="->"),
2828
)
29+
ax.annotate(
30+
"no arrow",
31+
xy=(0, 1),
32+
xycoords="data",
33+
xytext=(50, -30),
34+
textcoords="offset pixels",
35+
)
2936
return fig
3037

3138

test/test_annotate_reference.tex

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,18 +39,25 @@
3939
4.8 0.30901699437495
4040
};
4141
\draw[->,red] (axis cs:4.5,1.5) -- (axis cs:4,1);
42-
\node at (axis cs:4.5,1.5)[
42+
\draw (axis cs:4.5,1.5) node[
4343
scale=0.5,
4444
anchor=base west,
4545
text=black,
4646
rotate=0.0
4747
]{text};
48-
\node at (axis cs:-50,30)[
48+
\draw[->,black] (axis cs:0,1) ++(-50pt,30pt) -- (axis cs:0,1);
49+
\draw (axis cs:0,1) ++(-50pt,30pt) node[
4950
scale=0.5,
5051
anchor=base west,
5152
text=black,
5253
rotate=0.0
5354
]{arrowstyle};
55+
\draw (axis cs:0,1) ++(50px,-30px) node[
56+
scale=0.5,
57+
anchor=base west,
58+
text=black,
59+
rotate=0.0
60+
]{no arrow};
5461
\end{axis}
5562

5663
\end{tikzpicture}

test/test_arrows_reference.tex

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
\draw[draw=none,fill=color0] (axis cs:7.2,1.8) circle (0.2);
2828
\draw[draw=none,fill=color0] (axis cs:7.2,0.8) circle (0.2);
2929
\draw[-,black] (axis cs:2,6.8) -- (axis cs:3.2,6.8);
30-
\node at (axis cs:2,6.8)[
30+
\draw (axis cs:2,6.8) node[
3131
scale=0.7,
3232
fill=white,
3333
draw=black,
@@ -38,7 +38,7 @@
3838
rotate=0.0
3939
]{-};
4040
\draw[->,black] (axis cs:2,5.8) -- (axis cs:3.2,5.8);
41-
\node at (axis cs:2,5.8)[
41+
\draw (axis cs:2,5.8) node[
4242
scale=0.7,
4343
fill=white,
4444
draw=black,
@@ -49,7 +49,7 @@
4949
rotate=0.0
5050
]{-$>$};
5151
\draw[-|,black] (axis cs:2,4.8) -- (axis cs:3.2,4.8);
52-
\node at (axis cs:2,4.8)[
52+
\draw (axis cs:2,4.8) node[
5353
scale=0.7,
5454
fill=white,
5555
draw=black,
@@ -60,7 +60,7 @@
6060
rotate=0.0
6161
]{-[};
6262
\draw[-latex,black] (axis cs:2,3.8) -- (axis cs:3.2,3.8);
63-
\node at (axis cs:2,3.8)[
63+
\draw (axis cs:2,3.8) node[
6464
scale=0.7,
6565
fill=white,
6666
draw=black,
@@ -71,7 +71,7 @@
7171
rotate=0.0
7272
]{-$|$$>$};
7373
\draw[<-,black] (axis cs:2,2.8) -- (axis cs:3.2,2.8);
74-
\node at (axis cs:2,2.8)[
74+
\draw (axis cs:2,2.8) node[
7575
scale=0.7,
7676
fill=white,
7777
draw=black,
@@ -82,7 +82,7 @@
8282
rotate=0.0
8383
]{$<$-};
8484
\draw[<->,black] (axis cs:2,1.8) -- (axis cs:3.2,1.8);
85-
\node at (axis cs:2,1.8)[
85+
\draw (axis cs:2,1.8) node[
8686
scale=0.7,
8787
fill=white,
8888
draw=black,
@@ -93,7 +93,7 @@
9393
rotate=0.0
9494
]{$<$-$>$};
9595
\draw[latex-,black] (axis cs:2,0.8) -- (axis cs:3.2,0.8);
96-
\node at (axis cs:2,0.8)[
96+
\draw (axis cs:2,0.8) node[
9797
scale=0.7,
9898
fill=white,
9999
draw=black,
@@ -104,7 +104,7 @@
104104
rotate=0.0
105105
]{$<$$|$-};
106106
\draw[latex-latex,black] (axis cs:6,6.8) -- (axis cs:7.2,6.8);
107-
\node at (axis cs:6,6.8)[
107+
\draw (axis cs:6,6.8) node[
108108
scale=0.7,
109109
fill=white,
110110
draw=black,
@@ -115,7 +115,7 @@
115115
rotate=0.0
116116
]{$<$$|$-$|$$>$};
117117
\draw[|-,black] (axis cs:6,5.8) -- (axis cs:7.2,5.8);
118-
\node at (axis cs:6,5.8)[
118+
\draw (axis cs:6,5.8) node[
119119
scale=0.7,
120120
fill=white,
121121
draw=black,
@@ -126,7 +126,7 @@
126126
rotate=0.0
127127
]{]-};
128128
\draw[|-|,black] (axis cs:6,4.8) -- (axis cs:7.2,4.8);
129-
\node at (axis cs:6,4.8)[
129+
\draw (axis cs:6,4.8) node[
130130
scale=0.7,
131131
fill=white,
132132
draw=black,
@@ -137,7 +137,7 @@
137137
rotate=0.0
138138
]{]-[};
139139
\draw[-latex,very thick,black] (axis cs:6,3.8) -- (axis cs:7.2,3.8);
140-
\node at (axis cs:6,3.8)[
140+
\draw (axis cs:6,3.8) node[
141141
scale=0.7,
142142
fill=white,
143143
draw=black,
@@ -148,7 +148,7 @@
148148
rotate=0.0
149149
]{fancy};
150150
\draw[-latex,very thick,black] (axis cs:6,2.8) -- (axis cs:7.2,2.8);
151-
\node at (axis cs:6,2.8)[
151+
\draw (axis cs:6,2.8) node[
152152
scale=0.7,
153153
fill=white,
154154
draw=black,
@@ -159,7 +159,7 @@
159159
rotate=0.0
160160
]{simple};
161161
\draw[-latex,very thick,black] (axis cs:6,1.8) -- (axis cs:7.2,1.8);
162-
\node at (axis cs:6,1.8)[
162+
\draw (axis cs:6,1.8) node[
163163
scale=0.7,
164164
fill=white,
165165
draw=black,
@@ -170,7 +170,7 @@
170170
rotate=0.0
171171
]{wedge};
172172
\draw[|-|,black] (axis cs:6,0.8) -- (axis cs:7.2,0.8);
173-
\node at (axis cs:6,0.8)[
173+
\draw (axis cs:6,0.8) node[
174174
scale=0.7,
175175
fill=white,
176176
draw=black,

test/test_fancybox_reference.tex

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
--(axis cs:0.2,0.4)
2727
.. controls (axis cs:0.2,0.333333333333333) and (axis cs:0.233333333333333,0.3) .. (axis cs:0.3,0.3)
2828
--cycle;
29-
\node at (axis cs:0.1,0.8)[
29+
\draw (axis cs:0.1,0.8) node[
3030
scale=0.5,
3131
anchor=base west,
3232
text=black,
@@ -61,7 +61,7 @@
6161
--(axis cs:0.2,0.5)
6262
.. controls (axis cs:0.2,0.366666666666667) and (axis cs:0.266666666666667,0.3) .. (axis cs:0.4,0.3)
6363
--cycle;
64-
\node at (axis cs:0.1,0.8)[
64+
\draw (axis cs:0.1,0.8) node[
6565
scale=0.5,
6666
anchor=base west,
6767
text=black,
@@ -97,7 +97,7 @@
9797
--(axis cs:0.1,0.4)
9898
.. controls (axis cs:0.1,0.266666666666667) and (axis cs:0.166666666666667,0.2) .. (axis cs:0.3,0.2)
9999
--cycle;
100-
\node at (axis cs:0.1,0.8)[
100+
\draw (axis cs:0.1,0.8) node[
101101
scale=0.5,
102102
anchor=base west,
103103
text=black,
@@ -133,7 +133,7 @@
133133
--(axis cs:0,0.4)
134134
.. controls (axis cs:0,0.3) and (axis cs:0.1,0.25) .. (axis cs:0.3,0.25)
135135
--cycle;
136-
\node at (axis cs:0.1,0.8)[
136+
\draw (axis cs:0.1,0.8) node[
137137
scale=0.5,
138138
anchor=base west,
139139
text=black,

test/test_subplots_reference.tex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@
124124
};
125125
\end{groupplot}
126126

127-
\node at ({$(current bounding box.south west)!0.5!(current bounding box.south east)$}|-{$(current bounding box.south west)!0.98!(current bounding box.north west)$})[
127+
\draw ({$(current bounding box.south west)!0.5!(current bounding box.south east)$}|-{$(current bounding box.south west)!0.98!(current bounding box.north west)$}) node[
128128
scale=0.9,
129129
anchor=north,
130130
text=black,

test/test_text_overlay_reference.tex

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@
7070
5 25
7171
};
7272
\addlegendentry{a graph}
73-
\node at (axis cs:1,5)[
73+
\draw (axis cs:1,5) node[
7474
scale=2.5,
7575
fill=color1,
7676
draw=color2,
@@ -82,7 +82,7 @@
8282
text=red,
8383
rotate=30.0
8484
]{\itshape test1};
85-
\node at (axis cs:3,6)[
85+
\draw (axis cs:3,6) node[
8686
scale=2.5,
8787
fill=color1,
8888
draw=color2,
@@ -91,7 +91,7 @@
9191
text=blue,
9292
rotate=330.0
9393
]{\bfseries test2};
94-
\node at (axis cs:4,8)[
94+
\draw (axis cs:4,8) node[
9595
fill=color1,
9696
draw=color2,
9797
line width=0.4pt,
@@ -101,7 +101,7 @@
101101
text=blue,
102102
rotate=90.0
103103
]{\bfseries test3};
104-
\node at (axis cs:4,16)[
104+
\draw (axis cs:4,16) node[
105105
fill=color1,
106106
draw=color2,
107107
line width=0.4pt,
@@ -112,7 +112,7 @@
112112
text=blue,
113113
rotate=90.0
114114
]{\bfseries test4};
115-
\node at (axis cs:2,18)[
115+
\draw (axis cs:2,18) node[
116116
fill=color1,
117117
draw=color2,
118118
line width=0.4pt,
@@ -121,7 +121,7 @@
121121
text=blue,
122122
rotate=0.0
123123
]{test5};
124-
\node at (axis cs:1,20)[
124+
\draw (axis cs:1,20) node[
125125
fill=color1,
126126
draw=color2,
127127
line width=0.4pt,
@@ -130,7 +130,7 @@
130130
text=blue,
131131
rotate=0.0
132132
]{test6};
133-
\node at (axis cs:3,23)[
133+
\draw (axis cs:3,23) node[
134134
fill=color1,
135135
draw=color2,
136136
line width=0.4pt,
@@ -140,7 +140,7 @@
140140
text=blue,
141141
rotate=0.0
142142
]{test7};
143-
\node at (axis cs:3,20)[
143+
\draw (axis cs:3,20) node[
144144
fill=color1,
145145
draw=color2,
146146
line width=0.4pt,

0 commit comments

Comments
 (0)