Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Deprecate TextArea minimumdescent. #18528

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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 22, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
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
5 changes: 5 additions & 0 deletions doc/api/next_api_changes/deprecations/18528-AL.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
*minimumdescent* parameter/property of ``TextArea``
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
`.offsetbox.TextArea` has behaved as if *minimumdescent* was always True
(regardless of the value to which it was set) since Matplotlib 1.3, so the
parameter/property is deprecated.
7 changes: 2 additions & 5 deletions examples/misc/anchored_artists.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
class AnchoredText(AnchoredOffsetbox):
def __init__(self, s, loc, pad=0.4, borderpad=0.5,
prop=None, frameon=True):
self.txt = TextArea(s, minimumdescent=False)
self.txt = TextArea(s)
super().__init__(loc, pad=pad, borderpad=borderpad,
child=self.txt, prop=prop, frameon=frameon)

Expand Down Expand Up @@ -93,13 +93,10 @@ def __init__(self, transform, size, label, loc,
"""
self.size_bar = AuxTransformBox(transform)
self.size_bar.add_artist(Line2D([0, size], [0, 0], color="black"))

self.txt_label = TextArea(label, minimumdescent=False)

self.txt_label = TextArea(label)
self._box = VPacker(children=[self.size_bar, self.txt_label],
align="center",
pad=0, sep=sep)

super().__init__(loc, pad=pad, borderpad=borderpad,
child=self._box, prop=prop, frameon=frameon)

Expand Down
4 changes: 2 additions & 2 deletions examples/text_labels_and_annotations/demo_annotation_box.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
ax.plot(xy[0], xy[1], ".r")

# Annotate the 1st position with a text box ('Test 1')
offsetbox = TextArea("Test 1", minimumdescent=False)
offsetbox = TextArea("Test 1")

ab = AnnotationBbox(offsetbox, xy,
xybox=(-20, 40),
Expand All @@ -36,7 +36,7 @@
ax.add_artist(ab)

# Annotate the 1st position with another text box ('Test')
offsetbox = TextArea("Test", minimumdescent=False)
offsetbox = TextArea("Test")

ab = AnnotationBbox(offsetbox, xy,
xybox=(1.02, xy[1]),
Expand Down
9 changes: 1 addition & 8 deletions lib/matplotlib/legend.py
Original file line number Diff line number Diff line change
Expand Up @@ -755,8 +755,7 @@ def _init_legend_box(self, handles, labels, markerfirst=True):
handle_list.append(None)
else:
textbox = TextArea(lab, textprops=label_prop,
multilinebaseline=True,
minimumdescent=True)
multilinebaseline=True)
handlebox = DrawingArea(width=self.handlelength * fontsize,
height=height,
xdescent=0., ydescent=descent)
Expand Down Expand Up @@ -790,12 +789,6 @@ def _init_legend_box(self, handles, labels, markerfirst=True):
children=[h, t] if markerfirst else [t, h],
align="baseline")
for h, t in handles_and_labels[i0:i0 + di]]
# minimumdescent=False for the text of the last row of the column
if markerfirst:
itemBoxes[-1].get_children()[1].set_minimumdescent(False)
else:
itemBoxes[-1].get_children()[0].set_minimumdescent(False)

# pack columnBox
alignment = "baseline" if markerfirst else "right"
columnbox.append(VPacker(pad=0,
Expand Down
23 changes: 11 additions & 12 deletions lib/matplotlib/offsetbox.py
Original file line number Diff line number Diff line change
Expand Up @@ -775,6 +775,8 @@ class TextArea(OffsetBox):
width and height of the TextArea instance is the width and height of its
child text.
"""

@cbook._delete_parameter("3.4", "minimumdescent")
def __init__(self, s,
textprops=None,
multilinebaseline=None,
Expand All @@ -794,8 +796,9 @@ def __init__(self, s,
If `True`, baseline for multiline text is adjusted so that it is
(approximately) center-aligned with singleline text.

minimumdescent : bool, optional
If `True`, the box has a minimum descent of "p".
minimumdescent : bool, default: True
If `True`, the box has a minimum descent of "p". This is now
effectively always True.
"""
if textprops is None:
textprops = {}
Expand Down Expand Up @@ -835,16 +838,20 @@ def get_multilinebaseline(self):
"""
return self._multilinebaseline

@cbook.deprecated("3.4")
def set_minimumdescent(self, t):
"""
Set minimumdescent.

If True, extent of the single line text is adjusted so that
it has minimum descent of "p"
its descent is at least the one of the glyph "p".
"""
# The current implementation of Text._get_layout always behaves as if
# this is True.
self._minimumdescent = t
self.stale = True

@cbook.deprecated("3.4")
def get_minimumdescent(self):
"""
Get minimumdescent.
Expand Down Expand Up @@ -893,16 +900,8 @@ def get_extent(self, renderer):
yd_new = 0.5 * h - 0.5 * (h_ - d_)
self._baseline_transform.translate(0, yd - yd_new)
yd = yd_new

else: # single line

h_d = max(h_ - d_, h - yd)

if self.get_minimumdescent():
# To have a minimum descent, i.e., "l" and "p" have same
# descents.
yd = max(yd, d_)

h = h_d + yd

ha = self._text.get_horizontalalignment()
Expand Down Expand Up @@ -1300,7 +1299,7 @@ def __init__(self, s, loc, pad=0.4, borderpad=0.5, prop=None, **kwargs):
raise ValueError(
'Mixing verticalalignment with AnchoredText is not supported.')

self.txt = TextArea(s, textprops=prop, minimumdescent=False)
self.txt = TextArea(s, textprops=prop)
fp = self.txt._text.get_fontproperties()
super().__init__(
loc, pad=pad, borderpad=borderpad, child=self.txt, prop=fp,
Expand Down
5 changes: 1 addition & 4 deletions lib/mpl_toolkits/axes_grid1/anchored_artists.py
Original file line number Diff line number Diff line change
Expand Up @@ -337,10 +337,7 @@ def __init__(self, transform, size, label, loc,
else:
textprops = {'color': color, 'fontproperties': fontproperties}

self.txt_label = TextArea(
label,
minimumdescent=False,
textprops=textprops)
self.txt_label = TextArea(label, textprops=textprops)

if label_top:
_box_children = [self.txt_label, self.size_bar]
Expand Down