From e4f875a248cb1284fe0e8d47e499e1d1586ba5fc Mon Sep 17 00:00:00 2001 From: Antony Lee Date: Sat, 19 Sep 2020 12:50:59 +0200 Subject: [PATCH] Deprecate TextArea minimumdescent. The implementation of `Text._get_layout` has effectively enforced `minimumudescent=True` (`d = max(d, lp_d)`) since ee3af298 (mpl 1.3). --- .../deprecations/18528-AL.rst | 5 ++++ examples/misc/anchored_artists.py | 7 ++---- .../demo_annotation_box.py | 4 ++-- lib/matplotlib/legend.py | 9 +------- lib/matplotlib/offsetbox.py | 23 +++++++++---------- .../axes_grid1/anchored_artists.py | 5 +--- 6 files changed, 22 insertions(+), 31 deletions(-) create mode 100644 doc/api/next_api_changes/deprecations/18528-AL.rst diff --git a/doc/api/next_api_changes/deprecations/18528-AL.rst b/doc/api/next_api_changes/deprecations/18528-AL.rst new file mode 100644 index 000000000000..73674f8611b0 --- /dev/null +++ b/doc/api/next_api_changes/deprecations/18528-AL.rst @@ -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. diff --git a/examples/misc/anchored_artists.py b/examples/misc/anchored_artists.py index f2f7a6028ac1..80176e40f3ec 100644 --- a/examples/misc/anchored_artists.py +++ b/examples/misc/anchored_artists.py @@ -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) @@ -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) diff --git a/examples/text_labels_and_annotations/demo_annotation_box.py b/examples/text_labels_and_annotations/demo_annotation_box.py index cf94874509bf..0bb4179e7c6f 100644 --- a/examples/text_labels_and_annotations/demo_annotation_box.py +++ b/examples/text_labels_and_annotations/demo_annotation_box.py @@ -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), @@ -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]), diff --git a/lib/matplotlib/legend.py b/lib/matplotlib/legend.py index e643179ffc82..4553a605c67e 100644 --- a/lib/matplotlib/legend.py +++ b/lib/matplotlib/legend.py @@ -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) @@ -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, diff --git a/lib/matplotlib/offsetbox.py b/lib/matplotlib/offsetbox.py index 692c61d6f891..4e0b5d9815be 100644 --- a/lib/matplotlib/offsetbox.py +++ b/lib/matplotlib/offsetbox.py @@ -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, @@ -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 = {} @@ -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. @@ -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() @@ -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, diff --git a/lib/mpl_toolkits/axes_grid1/anchored_artists.py b/lib/mpl_toolkits/axes_grid1/anchored_artists.py index 9f200892580f..46309fa15c58 100644 --- a/lib/mpl_toolkits/axes_grid1/anchored_artists.py +++ b/lib/mpl_toolkits/axes_grid1/anchored_artists.py @@ -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]