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

Skip to content

Deprecate ContourLabeler.add_label_clabeltext. #26917

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 3, 2023
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
3 changes: 3 additions & 0 deletions doc/api/next_api_changes/behavior/26917-AL.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
``ContourLabeler.add_label`` now respects *use_clabeltext*
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
... and sets `.Text.set_transform_rotates_text` accordingly.
3 changes: 3 additions & 0 deletions doc/api/next_api_changes/deprecations/26917-AL.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
``ContourLabeler.add_label_clabeltext``
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
... is deprecated.
23 changes: 9 additions & 14 deletions lib/matplotlib/contour.py
Original file line number Diff line number Diff line change
Expand Up @@ -527,7 +527,7 @@ def calc_label_rot_and_inline(self, slc, ind, lw, lc=None, spacing=5):
return rotation, nlc

def add_label(self, x, y, rotation, lev, cvalue):
"""Add contour label without `.Text.set_transform_rotates_text`."""
"""Add a contour label, respecting whether *use_clabeltext* was set."""
data_x, data_y = self.axes.transData.inverted().transform((x, y))
t = Text(
data_x, data_y,
Expand All @@ -538,20 +538,21 @@ def add_label(self, x, y, rotation, lev, cvalue):
color=self.labelMappable.to_rgba(cvalue, alpha=self.get_alpha()),
fontproperties=self._label_font_props,
clip_box=self.axes.bbox)
if self._use_clabeltext:
data_rotation, = self.axes.transData.inverted().transform_angles(
[rotation], [[x, y]])
t.set(rotation=data_rotation, transform_rotates_text=True)
self.labelTexts.append(t)
self.labelCValues.append(cvalue)
self.labelXYs.append((x, y))
# Add label to plot here - useful for manual mode label selection
self.axes.add_artist(t)

@_api.deprecated("3.8", alternative="add_label")
def add_label_clabeltext(self, x, y, rotation, lev, cvalue):
"""Add contour label with `.Text.set_transform_rotates_text`."""
self.add_label(x, y, rotation, lev, cvalue)
# Grab the last added text, and reconfigure its rotation.
t = self.labelTexts[-1]
data_rotation, = self.axes.transData.inverted().transform_angles(
[rotation], [[x, y]])
t.set(rotation=data_rotation, transform_rotates_text=True)
with cbook._setattr_cm(self, _use_clabeltext=True):
self.add_label(x, y, rotation, lev, cvalue)

def add_label_near(self, x, y, inline=True, inline_spacing=5,
transform=None):
Expand Down Expand Up @@ -600,12 +601,6 @@ def pop_label(self, index=-1):
t.remove()

def labels(self, inline, inline_spacing):

if self._use_clabeltext:
add_label = self.add_label_clabeltext
else:
add_label = self.add_label

for idx, (icon, lev, cvalue) in enumerate(zip(
self.labelIndiceList,
self.labelLevelList,
Expand All @@ -622,7 +617,7 @@ def labels(self, inline, inline_spacing):
rotation, path = self._split_path_and_get_label_rotation(
subpath, idx, (x, y),
label_width, inline_spacing)
add_label(x, y, rotation, lev, cvalue) # Really add label.
self.add_label(x, y, rotation, lev, cvalue) # Really add label.
if inline: # If inline, add new contours
additions.append(path)
else: # If not adding label, keep old path
Expand Down