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

Annotation: always use FancyBboxPatch instead of bbox_artist#4178

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
tacaswell merged 9 commits intomatplotlib:masterfromefiring:annotate
Jul 22, 2015
Merged
Show file tree
Hide file tree
Changes from1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
PrevPrevious commit
NextNext commit
handle pad defaults; fix sizing of YAArrow substitute
  • Loading branch information
@efiring
efiring committedJul 20, 2015
commit2eb43133193b4583b5f40e98abca2e8b91522f39
10 changes: 6 additions & 4 deletionslib/matplotlib/tests/test_text.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -400,12 +400,14 @@ def test_text_with_arrow_annotation_get_window_extent():

@cleanup
def test_arrow_annotation_get_window_extent():
figure = Figure(dpi=100)
dpi = 100
dots_per_point = dpi / 72
figure = Figure(dpi=dpi)
figure.set_figwidth(2.0)
figure.set_figheight(2.0)
renderer = RendererAgg(200, 200, 100)

# Text annotation with arrow
# Text annotation with arrow; arrow dimensions are in points
annotation = Annotation(
'', xy=(0.0, 50.0), xytext=(50.0, 50.0), xycoords='figure pixels',
arrowprops={
Expand All@@ -417,9 +419,9 @@ def test_arrow_annotation_get_window_extent():
points = bbox.get_points()

eq_(bbox.width, 50.0)
assert_almost_equal(bbox.height, 10.0/ 0.72)
assert_almost_equal(bbox.height, 10.0* dots_per_point)
eq_(points[0, 0], 0.0)
eq_(points[0, 1], 50.0 - 5/ 0.72)
eq_(points[0, 1], 50.0 - 5* dots_per_point)


@cleanup
Expand Down
50 changes: 30 additions & 20 deletionslib/matplotlib/text.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -93,7 +93,8 @@ def get_rotation(rotation):
animated [True | False]
backgroundcolor any matplotlib color
bbox rectangle prop dict plus key 'pad' which is a
pad in points
pad in points; if a boxstyle is supplied, then
pad is instead a fraction of the font size
clip_box a matplotlib.transform.Bbox instance
clip_on [True | False]
color any matplotlib color
Expand DownExpand Up@@ -137,7 +138,7 @@ def get_rotation(rotation):
# function as a method with some refactoring of _get_layout method.


def _get_textbox(text, renderer, with_descent=True):
def _get_textbox(text, renderer):
"""
Calculate the bounding box of the text. Unlike
:meth:`matplotlib.text.Text.get_extents` method, The bbox size of
Expand DownExpand Up@@ -165,10 +166,6 @@ def _get_textbox(text, renderer, with_descent=True):
xt_box, yt_box = min(projected_xs), min(projected_ys)
w_box, h_box = max(projected_xs) - xt_box, max(projected_ys) - yt_box

if not with_descent:
yt_box += d
h_box -= d

tr = mtransforms.Affine2D().rotate(theta)

x_box, y_box = tr.transform_point((xt_box, yt_box))
Expand DownExpand Up@@ -228,7 +225,6 @@ def __init__(self,
self._multialignment = multialignment
self._rotation = rotation
self._fontproperties = fontproperties
self._bbox = None
self._bbox_patch = None # a FancyBboxPatch instance
self._renderer = None
if linespacing is None:
Expand All@@ -237,6 +233,14 @@ def __init__(self,
self.set_rotation_mode(rotation_mode)
self.update(kwargs)

def update(self, kwargs):
"""
Update properties from a dictionary.
"""
bbox = kwargs.pop('bbox', None)
super(Text, self).update(kwargs)
self.set_bbox(bbox) # depends on font properties

def __getstate__(self):
d = super(Text, self).__getstate__()
# remove the cached _renderer (if it exists)
Expand DownExpand Up@@ -484,12 +488,18 @@ def set_bbox(self, rectprops):

if rectprops is not None:
props = rectprops.copy()
pad = props.pop('pad', 4) # in points; hardwired default
boxstyle = props.pop("boxstyle", "square")
# If pad is in the boxstyle string, it will be passed
# directly to the FancyBboxPatch as font units.
if 'pad' not in boxstyle:
boxstyle += ",pad=%0.2f" % (pad / self.get_size())
boxstyle = props.pop("boxstyle", None)
pad = props.pop("pad", None)
if boxstyle is None:
boxstyle = "square"
if pad is None:
pad = 4 # points
pad /= self.get_size() # to fraction of font size
else:
if pad is None:
pad = 0.3
if "pad" not in boxstyle:
boxstyle += ",pad=%0.2f" % pad

bbox_transmuter = props.pop("bbox_transmuter", None)

Expand DownExpand Up@@ -530,8 +540,7 @@ def update_bbox_position_size(self, renderer):

posx, posy = trans.transform_point((posx, posy))

x_box, y_box, w_box, h_box = _get_textbox(self, renderer,
with_descent=True)
x_box, y_box, w_box, h_box = _get_textbox(self, renderer)
self._bbox_patch.set_bounds(0., 0., w_box, h_box)
theta = np.deg2rad(self.get_rotation())
tr = mtransforms.Affine2D().rotate(theta)
Expand All@@ -547,8 +556,7 @@ def _draw_bbox(self, renderer, posx, posy):
(FancyBboxPatch), and draw
"""

x_box, y_box, w_box, h_box = _get_textbox(self, renderer,
with_descent=True)
x_box, y_box, w_box, h_box = _get_textbox(self, renderer)
self._bbox_patch.set_bounds(0., 0., w_box, h_box)
theta = np.deg2rad(self.get_rotation())
tr = mtransforms.Affine2D().rotate(theta)
Expand DownExpand Up@@ -2143,9 +2151,11 @@ def _update_position_xytext(self, renderer, xy_pixel):
" use 'headlength' to set the head length in points.")
headlength = d.pop('headlength', 12)

stylekw = dict(head_length=headlength / ms,
head_width=headwidth / ms,
tail_width=width / ms)
to_style = self.figure.dpi / (72 * ms)

stylekw = dict(head_length=headlength * to_style,
head_width=headwidth * to_style,
tail_width=width * to_style)

self.arrow_patch.set_arrowstyle('simple', **stylekw)

Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp