8000 Deprecate some label-related attributes on ContourLabeler. by anntzer · Pull Request #24144 · matplotlib/matplotlib · GitHub
[go: up one dir, main page]

Skip to content

Deprecate some label-related attributes on ContourLabeler. #24144

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
Oct 15, 2022
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/24144-AL.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
``ContourLabeler`` attributes
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
The ``labelFontProps``, ``labelFontSizeList``, and ``labelTextsList``
attributes of `.ContourLabeler` have been deprecated. Use the ``labelTexts``
attribute and the font properties of the corresponding text objects instead.
46 changes: 28 additions & 18 deletions lib/matplotlib/contour.py
Original file line number Diff line number Diff line change
Expand Up @@ -201,10 +201,7 @@ def clabel(self, levels=None, *,
self.labelLevelList = levels
self.labelIndiceList = indices

self.labelFontProps = font_manager.FontProperties()
self.labelFontProps.set_size(fontsize)
font_size_pts = self.labelFontProps.get_size_in_points()
self.labelFontSizeList = [font_size_pts] * len(levels)
self._label_font_props = font_manager.FontProperties(size=fontsize)

if colors is None:
self.labelMappable = self
Expand All @@ -217,10 +214,10 @@ def clabel(self, levels=None, *,

self.labelXYs = []

if np.iterable(self.labelManual):
for x, y in self.labelManual:
if np.iterable(manual):
for x, y in manual:
self.add_label_near(x, y, inline, inline_spacing)
elif self.labelManual:
elif manual:
print('Select label locations manually using first mouse button.')
print('End manual selection with second mouse button.')
if not inline:
Expand All @@ -233,8 +230,23 @@ def clabel(self, levels=None, *,
else:
self.labels(inline, inline_spacing)

self.labelTextsList = cbook.silent_list('text.Text', self.labelTexts)
return self.labelTextsList
return cbook.silent_list('text.Text', self.labelTexts)

@_api.deprecated("3.7", alternative="cs.labelTexts[0].get_font()")
@property
def labelFontProps(self):
return self._label_font_props

@_api.deprecated("3.7", alternative=(
"[cs.labelTexts[0].get_font().get_size()] * len(cs.labelLevelList)"))
@property
def labelFontSizeList(self):
return [self._label_font_props.get_size()] * len(self.labelLevelList)

@_api.deprecated("3.7", alternative="cs.labelTexts")
@property
def labelTextsList(self):
return cbook.silent_list('text.Text', self.labelTexts)

def print_label(self, linecontour, labelwidth):
"""Return whether a contour is long enough to hold a label."""
Expand All @@ -251,12 +263,10 @@ def _get_nth_label_width(self, nth):
"""Return the width of the *nth* label, in pixels."""
fig = self.axes.figure
renderer = fig._get_renderer()
return (
Text(0, 0, self.get_text(self.labelLevelList[nth], self.labelFmt),
figure=fig,
size=self.labelFontSizeList[nth],
fontproperties=self.labelFontProps)
.get_window_extent(renderer).width)
return (Text(0, 0,
self.get_text(self.labelLevelList[nth], self.labelFmt),
figure=fig, fontproperties=self._label_font_props)
.get_window_extent(renderer).width)

@_api.deprecated("3.5")
def get_label_width(self, lev, fmt, fsize):
Expand All @@ -266,7 +276,7 @@ def get_label_width(self, lev, fmt, fsize):
fig = self.axes.figure
renderer = fig._get_renderer()
width = (Text(0, 0, lev, figure=fig,
size=fsize, fontproperties=self.labelFontProps)
size=fsize, fontproperties=self._label_font_props)
.get_window_extent(renderer).width)
width *= 72 / fig.dpi
return width
Expand All @@ -276,7 +286,7 @@ def set_label_props(self, label, text, color):
"""Set the label properties - color, fontsize, text."""
label.set_text(text)
label.set_color(color)
label.set_fontproperties(self.labelFontProps)
label.set_fontproperties(self._label_font_props)
label.set_clip_box(self.axes.bbox)

def get_text(self, lev, fmt):
Expand Down Expand Up @@ -426,7 +436,7 @@ def add_label(self, x, y, rotation, lev, cvalue):
horizontalalignment='center', verticalalignment='center',
zorder=self._clabel_zorder,
color=self.labelMappable.to_rgba(cvalue, alpha=self.alpha),
fontproperties=self.labelFontProps,
fontproperties=self._label_font_props,
clip_box=self.axes.bbox)
self.labelTexts.append(t)
self.labelCValues.append(cvalue)
Expand Down
0