Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit7b71257

Browse files
committed
Revert " Merge pull request#4019 from myshen/annot_neg_coords"
This reverts commitd6e1577, reversingchanges made tob280f7d.For 1.4.0 tacaswell refactored annotations (#2351 ) but missed that{'axes points', 'axes pixel', 'figure points', 'figure pixel'} werespecial cased to wrap. Presumably from the function name to maintainback compatibility. This was an unintentional and undocumented APIbreak.This API break was noticed in#4012 and fixed in#4019 but that catchestoo many of the coordinate systems (should not be all things that startwith 'axes') so fixed one API, but broke others.There were two reasonable courses of action: 1. revert back to 1.4.2 behavior with nothing wrapping. 2. revert back to 1.3.1 behavior with somethings wrapping.In the discussion in#4292 where the consensus was to go withoption 1, hence this reversion.
1 parent263c06a commit7b71257

File tree

3 files changed

+6
-186
lines changed

3 files changed

+6
-186
lines changed
Binary file not shown.

‎lib/matplotlib/tests/test_text.py

Lines changed: 0 additions & 169 deletions
Original file line numberDiff line numberDiff line change
@@ -305,177 +305,8 @@ def test_get_rotation_mod360():
305305
fori,jinzip([360.,377.,720+177.2], [0.,17.,177.2]):
306306
assert_almost_equal(text.get_rotation(i),j)
307307

308-
309308
@image_comparison(baseline_images=['text_bboxclip'])
310309
deftest_bbox_clipping():
311310
plt.text(0.9,0.2,'Is bbox clipped?',backgroundcolor='r',clip_on=True)
312311
t=plt.text(0.9,0.5,'Is fancy bbox clipped?',clip_on=True)
313312
t.set_bbox({"boxstyle":"round, pad=0.1"})
314-
315-
316-
@image_comparison(baseline_images=['annotation_negative_coords'],
317-
extensions=['png'])
318-
deftest_annotation_negative_coords():
319-
fig=plt.figure()
320-
ax=plt.subplot(1,1,1)
321-
322-
ax.annotate("+fpt", (15,40),xycoords="figure points")
323-
ax.annotate("+fpx", (25,30),xycoords="figure pixels")
324-
ax.annotate("+apt", (35,20),xycoords="axes points")
325-
ax.annotate("+apx", (45,10),xycoords="axes pixels")
326-
327-
ax.annotate("-fpt", (-55,-40),xycoords="figure points")
328-
ax.annotate("-fpx", (-45,-30),xycoords="figure pixels")
329-
ax.annotate("-apt", (-35,-20),xycoords="axes points")
330-
ax.annotate("-apx", (-25,-10),xycoords="axes pixels")
331-
332-
333-
@cleanup
334-
deftest_text_annotation_get_window_extent():
335-
figure=Figure(dpi=100)
336-
renderer=RendererAgg(200,200,100)
337-
338-
# Only text annotation
339-
annotation=Annotation('test',xy=(0,0))
340-
annotation.set_figure(figure)
341-
342-
text=Text(text='test',x=0,y=0)
343-
text.set_figure(figure)
344-
345-
bbox=annotation.get_window_extent(renderer=renderer)
346-
347-
text_bbox=text.get_window_extent(renderer=renderer)
348-
eq_(bbox.width,text_bbox.width)
349-
eq_(bbox.height,text_bbox.height)
350-
351-
_,_,d=renderer.get_text_width_height_descent(
352-
'text',annotation._fontproperties,ismath=False)
353-
_,_,lp_d=renderer.get_text_width_height_descent(
354-
'lp',annotation._fontproperties,ismath=False)
355-
below_line=max(d,lp_d)
356-
357-
# These numbers are specific to the current implementation of Text
358-
points=bbox.get_points()
359-
eq_(points[0,0],0.0)
360-
eq_(points[1,0],text_bbox.width)
361-
eq_(points[0,1],-below_line)
362-
eq_(points[1,1],text_bbox.height-below_line)
363-
364-
365-
@cleanup
366-
deftest_text_with_arrow_annotation_get_window_extent():
367-
headwidth=21
368-
fig,ax=plt.subplots(dpi=100)
369-
txt=ax.text(s='test',x=0,y=0)
370-
ann=ax.annotate(
371-
'test',
372-
xy=(0.0,50.0),
373-
xytext=(50.0,50.0),xycoords='figure pixels',
374-
arrowprops={
375-
'facecolor':'black','width':2,
376-
'headwidth':headwidth,'shrink':0.0})
377-
378-
plt.draw()
379-
renderer=fig.canvas.renderer
380-
# bounding box of text
381-
text_bbox=txt.get_window_extent(renderer=renderer)
382-
# bounding box of annotation (text + arrow)
383-
bbox=ann.get_window_extent(renderer=renderer)
384-
# bounding box of arrow
385-
arrow_bbox=ann.arrow_patch.get_window_extent(renderer)
386-
# bounding box of annotation text
387-
ann_txt_bbox=Text.get_window_extent(ann)
388-
389-
# make sure annotation width is 50 px wider than
390-
# just the text
391-
eq_(bbox.width,text_bbox.width+50.0)
392-
# make sure the annotation text bounding box is same size
393-
# as the bounding box of the same string as a Text object
394-
eq_(ann_txt_bbox.height,text_bbox.height)
395-
eq_(ann_txt_bbox.width,text_bbox.width)
396-
# compute the expected bounding box of arrow + text
397-
expected_bbox=Bbox.union([ann_txt_bbox,arrow_bbox])
398-
assert_almost_equal(bbox.height,expected_bbox.height)
399-
400-
401-
@cleanup
402-
deftest_arrow_annotation_get_window_extent():
403-
dpi=100
404-
dots_per_point=dpi/72
405-
figure=Figure(dpi=dpi)
406-
figure.set_figwidth(2.0)
407-
figure.set_figheight(2.0)
408-
renderer=RendererAgg(200,200,100)
409-
410-
# Text annotation with arrow; arrow dimensions are in points
411-
annotation=Annotation(
412-
'',xy=(0.0,50.0),xytext=(50.0,50.0),xycoords='figure pixels',
413-
arrowprops={
414-
'facecolor':'black','width':8,'headwidth':10,'shrink':0.0})
415-
annotation.set_figure(figure)
416-
annotation.draw(renderer)
417-
418-
bbox=annotation.get_window_extent()
419-
points=bbox.get_points()
420-
421-
eq_(bbox.width,50.0)
422-
assert_almost_equal(bbox.height,10.0*dots_per_point)
423-
eq_(points[0,0],0.0)
424-
eq_(points[0,1],50.0-5*dots_per_point)
425-
426-
427-
@cleanup
428-
deftest_empty_annotation_get_window_extent():
429-
figure=Figure(dpi=100)
430-
figure.set_figwidth(2.0)
431-
figure.set_figheight(2.0)
432-
renderer=RendererAgg(200,200,100)
433-
434-
# Text annotation with arrow
435-
annotation=Annotation(
436-
'',xy=(0.0,50.0),xytext=(0.0,50.0),xycoords='figure pixels')
437-
annotation.set_figure(figure)
438-
annotation.draw(renderer)
439-
440-
bbox=annotation.get_window_extent()
441-
points=bbox.get_points()
442-
443-
eq_(points[0,0],0.0)
444-
eq_(points[1,0],0.0)
445-
eq_(points[1,1],50.0)
446-
eq_(points[0,1],50.0)
447-
448-
449-
@image_comparison(baseline_images=['basictext_wrap'],
450-
extensions=['png'])
451-
deftest_basic_wrap():
452-
fig=plt.figure()
453-
plt.axis([0,10,0,10])
454-
t="This is a really long string that I'd rather have wrapped so that" \
455-
" it doesn't go outside of the figure, but if it's long enough it" \
456-
" will go off the top or bottom!"
457-
plt.text(4,1,t,ha='left',rotation=15,wrap=True)
458-
plt.text(6,5,t,ha='left',rotation=15,wrap=True)
459-
plt.text(5,5,t,ha='right',rotation=-15,wrap=True)
460-
plt.text(5,10,t,fontsize=18,style='oblique',ha='center',
461-
va='top',wrap=True)
462-
plt.text(3,4,t,family='serif',style='italic',ha='right',wrap=True)
463-
plt.text(-1,0,t,ha='left',rotation=-15,wrap=True)
464-
465-
466-
@image_comparison(baseline_images=['fonttext_wrap'],
467-
extensions=['png'])
468-
deftest_font_wrap():
469-
fig=plt.figure()
470-
plt.axis([0,10,0,10])
471-
t="This is a really long string that I'd rather have wrapped so that" \
472-
" it doesn't go outside of the figure, but if it's long enough it" \
473-
" will go off the top or bottom!"
474-
plt.text(4,-1,t,fontsize=18,family='serif',ha='left',rotation=15,
475-
wrap=True)
476-
plt.text(6,5,t,family='sans serif',ha='left',rotation=15,wrap=True)
477-
plt.text(5,5,t,weight='light',ha='right',rotation=-15,wrap=True)
478-
plt.text(5,10,t,weight='heavy',ha='center',va='top',wrap=True)
479-
plt.text(3,4,t,family='monospace',ha='right',wrap=True)
480-
plt.text(-1,0,t,fontsize=14,style='italic',ha='left',rotation=-15,
481-
wrap=True)

‎lib/matplotlib/text.py

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1704,17 +1704,17 @@ def _get_xy(self, renderer, x, y, s):
17041704
ifs2=='data':
17051705
y=float(self.convert_yunits(y))
17061706

1707-
tr=self._get_xy_transform(renderer,(x,y),s)
1707+
tr=self._get_xy_transform(renderer,s)
17081708
x1,y1=tr.transform_point((x,y))
17091709
returnx1,y1
17101710

1711-
def_get_xy_transform(self,renderer,xy,s):
1711+
def_get_xy_transform(self,renderer,s):
17121712

17131713
ifisinstance(s,tuple):
17141714
s1,s2=s
17151715
frommatplotlib.transformsimportblended_transform_factory
1716-
tr1=self._get_xy_transform(renderer,xy,s1)
1717-
tr2=self._get_xy_transform(renderer,xy,s2)
1716+
tr1=self._get_xy_transform(renderer,s1)
1717+
tr2=self._get_xy_transform(renderer,s2)
17181718
tr=blended_transform_factory(tr1,tr2)
17191719
returntr
17201720

@@ -1763,17 +1763,7 @@ def _get_xy_transform(self, renderer, xy, s):
17631763
# bbox0 = self._get_bbox(renderer, bbox)
17641764

17651765
ifbbox0isnotNone:
1766-
x,y=xy
1767-
bounds=bbox0.extents
1768-
ifx<0:
1769-
x0=bounds[2]
1770-
else:
1771-
x0=bounds[0]
1772-
ify<0:
1773-
y0=bounds[3]
1774-
else:
1775-
y0=bounds[1]
1776-
xy0= (x0,y0)
1766+
xy0=bbox0.bounds[:2]
17771767
elifbbox_name=="offset":
17781768
xy0=self._get_ref_xy(renderer)
17791769

@@ -2120,8 +2110,7 @@ def _update_position_xytext(self, renderer, xy_pixel):
21202110
patch.
21212111
"""
21222112
# generate transformation,
2123-
self.set_transform(self._get_xy_transform(
2124-
renderer,self.xy,self.anncoords))
2113+
self.set_transform(self._get_xy_transform(renderer,self.anncoords))
21252114

21262115
ox0,oy0=self._get_xy_display()
21272116
ox1,oy1=xy_pixel

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp