Skip to content

Commit f8e4b83

Browse files
itziakostacaswell
authored andcommitted
remove duplicate imports and pyflakes cleanup
Conflicts: lib/matplotlib/tests/test_text.py
1 parent be652cd commit f8e4b83

File tree

1 file changed

+104
-95
lines changed

1 file changed

+104
-95
lines changed

lib/matplotlib/tests/test_text.py

+104-95
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,19 @@
22
unicode_literals)
33

44
import six
5+
import warnings
56

67
import numpy as np
8+
from numpy.testing import assert_almost_equal
9+
from nose import SkipTest
10+
from nose.tools import assert_raises, eq_
11+
712
import matplotlib
8-
from matplotlib.testing.decorators import image_comparison, knownfailureif, cleanup
913
import matplotlib.pyplot as plt
10-
import warnings
11-
from nose import SkipTest
12-
from nose.tools import with_setup, assert_raises, eq_, ok_
14+
from matplotlib.testing.decorators import image_comparison, cleanup
15+
from matplotlib.figure import Figure
16+
from matplotlib.text import Annotation, Text
17+
from matplotlib.backends.backend_agg import RendererAgg
1318

1419

1520
@image_comparison(baseline_images=['font_styles'])
@@ -23,79 +28,98 @@ def find_matplotlib_font(**kw):
2328
return FontProperties(fname=path)
2429

2530
from matplotlib.font_manager import FontProperties, findfont
26-
warnings.filterwarnings('ignore', ('findfont: Font family \[u?\'Foo\'\] '+
27-
'not found. Falling back to .'),
28-
UserWarning,
29-
module='matplotlib.font_manager')
30-
fig = plt.figure()
31+
warnings.filterwarnings(
32+
'ignore',
33+
('findfont: Font family \[u?\'Foo\'\] not found. Falling back to .'),
34+
UserWarning,
35+
module='matplotlib.font_manager')
36+
37+
plt.figure()
3138
ax = plt.subplot(1, 1, 1)
3239

33-
normalFont = find_matplotlib_font(family="sans-serif",
34-
style="normal",
35-
variant="normal",
36-
size=14,
37-
)
38-
ax.annotate("Normal Font", (0.1, 0.1), xycoords='axes fraction',
39-
fontproperties=normalFont)
40-
41-
boldFont = find_matplotlib_font(family="Foo",
42-
style="normal",
43-
variant="normal",
44-
weight="bold",
45-
stretch=500,
46-
size=14,
47-
)
48-
ax.annotate("Bold Font", (0.1, 0.2), xycoords='axes fraction',
49-
fontproperties=boldFont)
50-
51-
boldItemFont = find_matplotlib_font(family="sans serif",
52-
style="italic",
53-
variant="normal",
54-
weight=750,
55-
stretch=500,
56-
size=14,
57-
)
58-
ax.annotate("Bold Italic Font", (0.1, 0.3), xycoords='axes fraction',
59-
fontproperties=boldItemFont)
60-
61-
lightFont = find_matplotlib_font(family="sans-serif",
62-
style="normal",
63-
variant="normal",
64-
weight=200,
65-
stretch=500,
66-
size=14,
67-
)
68-
ax.annotate("Light Font", (0.1, 0.4), xycoords='axes fraction',
69-
fontproperties=lightFont)
70-
71-
condensedFont = find_matplotlib_font(family="sans-serif",
72-
style="normal",
73-
variant="normal",
74-
weight=500,
75-
stretch=100,
76-
size=14,
77-
)
78-
ax.annotate("Condensed Font", (0.1, 0.5), xycoords='axes fraction',
79-
fontproperties=condensedFont)
40+
normalFont = find_matplotlib_font(
41+
family="sans-serif",
42+
style="normal",
43+
variant="normal",
44+
size=14)
45+
ax.annotate(
46+
"Normal Font",
47+
(0.1, 0.1),
48+
xycoords='axes fraction',
49+
fontproperties=normalFont)
50+
51+
boldFont = find_matplotlib_font(
52+
family="Foo",
53+
style="normal",
54+
variant="normal",
55+
weight="bold",
56+
stretch=500,
57+
size=14)
58+
ax.annotate(
59+
"Bold Font",
60+
(0.1, 0.2),
61+
xycoords='axes fraction',
62+
fontproperties=boldFont)
63+
64+
boldItemFont = find_matplotlib_font(
65+
family="sans serif",
66+
style="italic",
67+
variant="normal",
68+
weight=750,
69+
stretch=500,
70+
size=14)
71+
ax.annotate(
72+
"Bold Italic Font",
73+
(0.1, 0.3),
74+
xycoords='axes fraction',
75+
fontproperties=boldItemFont)
76+
77+
lightFont = find_matplotlib_font(
78+
family="sans-serif",
79+
style="normal",
80+
variant="normal",
81+
weight=200,
82+
stretch=500,
83+
size=14)
84+
ax.annotate(
85+
"Light Font",
86+
(0.1, 0.4),
87+
xycoords='axes fraction',
88+
fontproperties=lightFont)
89+
90+
condensedFont = find_matplotlib_font(
91+
family="sans-serif",
92+
style="normal",
93+
variant="normal",
94+
weight=500,
95+
stretch=100,
96+
size=14)
97+
ax.annotate(
98+
"Condensed Font",
99+
(0.1, 0.5),
100+
xycoords='axes fraction',
101+
fontproperties=condensedFont)
80102

81103
ax.set_xticks([])
82104
ax.set_yticks([])
83105

84106

85107
@image_comparison(baseline_images=['multiline'])
86108
def test_multiline():
87-
fig = plt.figure()
109+
plt.figure()
88110
ax = plt.subplot(1, 1, 1)
89111
ax.set_title("multiline\ntext alignment")
90112

91-
plt.text(0.2, 0.5, "TpTpTp\n$M$\nTpTpTp", size=20,
92-
ha="center", va="top")
113+
plt.text(
114+
0.2, 0.5, "TpTpTp\n$M$\nTpTpTp", size=20, ha="center", va="top")
93115

94-
plt.text(0.5, 0.5, "TpTpTp\n$M^{M^{M^{M}}}$\nTpTpTp", size=20,
95-
ha="center", va="top")
116+
plt.text(
117+
0.5, 0.5, "TpTpTp\n$M^{M^{M^{M}}}$\nTpTpTp", size=20,
118+
ha="center", va="top")
96119

97-
plt.text(0.8, 0.5, "TpTpTp\n$M_{q_{q_{q}}}$\nTpTpTp", size=20,
98-
ha="center", va="top")
120+
plt.text(
121+
0.8, 0.5, "TpTpTp\n$M_{q_{q_{q}}}$\nTpTpTp", size=20,
122+
ha="center", va="top")
99123

100124
plt.xlim(0, 1)
101125
plt.ylim(0, 0.8)
@@ -136,15 +160,15 @@ def test_contains():
136160
fig = plt.figure()
137161
ax = plt.axes()
138162

139-
mevent = mbackend.MouseEvent('button_press_event', fig.canvas, 0.5,
140-
0.5, 1, None)
163+
mevent = mbackend.MouseEvent(
164+
'button_press_event', fig.canvas, 0.5, 0.5, 1, None)
141165

142166
xs = np.linspace(0.25, 0.75, 30)
143167
ys = np.linspace(0.25, 0.75, 30)
144168
xs, ys = np.meshgrid(xs, ys)
145169

146-
txt = plt.text(0.48, 0.52, 'hello world', ha='center', fontsize=30,
147-
rotation=30)
170+
txt = plt.text(
171+
0.48, 0.52, 'hello world', ha='center', fontsize=30, rotation=30)
148172
# uncomment to draw the text's bounding box
149173
# txt.set_bbox(dict(edgecolor='black', facecolor='none'))
150174

@@ -154,9 +178,7 @@ def test_contains():
154178

155179
for x, y in zip(xs.flat, ys.flat):
156180
mevent.x, mevent.y = plt.gca().transAxes.transform_point([x, y])
157-
158181
contains, _ = txt.contains(mevent)
159-
160182
color = 'yellow' if contains else 'red'
161183

162184
# capture the viewLim, plot a point, and reset the viewLim
@@ -168,7 +190,7 @@ def test_contains():
168190
@image_comparison(baseline_images=['titles'])
169191
def test_titles():
170192
# left and right side titles
171-
fig = plt.figure()
193+
plt.figure()
172194
ax = plt.subplot(1, 1, 1)
173195
ax.set_title("left title", loc="left")
174196
ax.set_title("right title", loc="right")
@@ -178,15 +200,17 @@ def test_titles():
178200

179201
@image_comparison(baseline_images=['text_alignment'])
180202
def test_alignment():
181-
fig = plt.figure()
203+
plt.figure()
182204
ax = plt.subplot(1, 1, 1)
183205

184206
x = 0.1
185207
for rotation in (0, 30):
186208
for alignment in ('top', 'bottom', 'baseline', 'center'):
187-
ax.text(x, 0.5, alignment + " Tj", va=alignment, rotation=rotation,
188-
bbox=dict(boxstyle='round', facecolor='wheat', alpha=0.5))
189-
ax.text(x, 1.0, r'$\sum_{i=0}^{j}$', va=alignment, rotation=rotation)
209+
ax.text(
210+
x, 0.5, alignment + " Tj", va=alignment, rotation=rotation,
211+
bbox=dict(boxstyle='round', facecolor='wheat', alpha=0.5))
212+
ax.text(
213+
x, 1.0, r'$\sum_{i=0}^{j}$', va=alignment, rotation=rotation)
190214
x += 0.1
191215

192216
ax.plot([0, 1], [0.5, 0.5])
@@ -201,8 +225,8 @@ def test_alignment():
201225
@image_comparison(baseline_images=['axes_titles'], extensions=['png'])
202226
def test_axes_titles():
203227
# Related to issue #3327
204-
fig = plt.figure()
205-
ax = plt.subplot(1,1,1)
228+
plt.figure()
229+
ax = plt.subplot(1, 1, 1)
206230
ax.set_title('center', loc='center', fontsize=20, fontweight=700)
207231
ax.set_title('left', loc='left', fontsize=12, fontweight=400)
208232
ax.set_title('right', loc='right', fontsize=12, fontweight=400)
@@ -213,7 +237,8 @@ def test_set_position():
213237
fig, ax = plt.subplots()
214238

215239
# test set_position
216-
ann = ax.annotate('test', (0, 0), xytext=(0, 0), textcoords='figure pixels')
240+
ann = ax.annotate(
241+
'test', (0, 0), xytext=(0, 0), textcoords='figure pixels')
217242
plt.draw()
218243

219244
init_pos = ann.get_window_extent(fig.canvas.renderer)
@@ -226,7 +251,8 @@ def test_set_position():
226251
assert a + shift_val == b
227252

228253
# test xyann
229-
ann = ax.annotate('test', (0, 0), xytext=(0, 0), textcoords='figure pixels')
254+
ann = ax.annotate(
255+
'test', (0, 0), xytext=(0, 0), textcoords='figure pixels')
230256
plt.draw()
231257

232258
init_pos = ann.get_window_extent(fig.canvas.renderer)
@@ -264,14 +290,9 @@ def test_annotation_negative_coords():
264290

265291

266292
def test_text_annotation_get_window_extent():
267-
from matplotlib.figure import Figure
268-
from matplotlib.text import Annotation, Text
269-
from matplotlib.backends.backend_agg import RendererAgg
270-
271293
figure = Figure(dpi=100)
272294
renderer = RendererAgg(200, 200, 100)
273295

274-
275296
# Only text annotation
276297
annotation = Annotation('test', xy=(0, 0))
277298
annotation.set_figure(figure)
@@ -300,10 +321,6 @@ def test_text_annotation_get_window_extent():
300321

301322

302323
def test_text_with_arrow_annotation_get_window_extent():
303-
from matplotlib.figure import Figure
304-
from matplotlib.text import Annotation, Text
305-
from matplotlib.backends.backend_agg import RendererAgg
306-
307324
figure = Figure(dpi=100)
308325
renderer = RendererAgg(600, 600, 100)
309326
headwidth = 21
@@ -330,10 +347,6 @@ def test_text_with_arrow_annotation_get_window_extent():
330347

331348

332349
def test_arrow_annotation_get_window_extent():
333-
from matplotlib.figure import Figure
334-
from matplotlib.text import Annotation
335-
from matplotlib.backends.backend_agg import RendererAgg
336-
337350
figure = Figure(dpi=100)
338351
figure.set_figwidth(2.0)
339352
figure.set_figheight(2.0)
@@ -357,10 +370,6 @@ def test_arrow_annotation_get_window_extent():
357370

358371

359372
def test_empty_annotation_get_window_extent():
360-
from matplotlib.figure import Figure
361-
from matplotlib.text import Annotation
362-
from matplotlib.backends.backend_agg import RendererAgg
363-
364373
figure = Figure(dpi=100)
365374
figure.set_figwidth(2.0)
366375
figure.set_figheight(2.0)

0 commit comments

Comments
 (0)