Removal of deprecations for Contour by DHClimber · Pull Request #26907 · matplotlib/matplotlib · GitHub
Skip to content
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
2 changes: 1 addition & 1 deletion doc/api/artist_api.rst
14 changes: 14 additions & 0 deletions doc/api/next_api_changes/removals/26907-DCH.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
``contour.ClabelText`` and ``ContourLabeler.set_label_props``
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
... are removed.

Use ``Text(..., transform_rotates_text=True)`` as a replacement for
``contour.ClabelText(...)`` and ``text.set(text=text, color=color,
fontproperties=labeler.labelFontProps, clip_box=labeler.axes.bbox)`` as a
replacement for the ``ContourLabeler.set_label_props(label, text, color)``.

``ContourLabeler`` attributes
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Comment thread
DHClimber marked this conversation as resolved.
The ``labelFontProps``, ``labelFontSizeList``, and ``labelTextsList``
attributes of `.ContourLabeler` have been removed. Use the ``labelTexts``
attribute and the font properties of the corresponding text objects instead.
38 changes: 0 additions & 38 deletions lib/matplotlib/contour.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,20 +25,6 @@
import matplotlib.transforms as mtransforms


@_api.deprecated("3.7", alternative="Text.set_transform_rotates_text")
class ClabelText(Text):
"""
Unlike the ordinary text, the get_rotation returns an updated
angle in the pixel coordinate assuming that the input rotation is
an angle in data coordinate (or whatever transform set).
"""

def get_rotation(self):
new_angle, = self.get_transform().transform_angles(
[super().get_rotation()], [self.get_position()])
return new_angle


def _contour_labeler_event_handler(cs, inline, inline_spacing, event):
canvas = cs.axes.figure.canvas
is_button = event.name == "button_press_event"
Expand Down Expand Up @@ -223,22 +209,6 @@ def clabel(self, levels=None, *,

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."""
return (len(linecontour) > 10 * labelwidth
Expand All @@ -260,14 +230,6 @@ def _get_nth_label_width(self, nth):
figure=fig, fontproperties=self._label_font_props)
.get_window_extent(renderer).width)

@_api.deprecated("3.7", alternative="Artist.set")
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._label_font_props)
label.set_clip_box(self.axes.bbox)

def get_text(self, lev, fmt):
"""Get the text of the label."""
if isinstance(lev, str):
Expand Down
9 changes: 1 addition & 8 deletions lib/matplotlib/contour.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ from collections.abc import Callable, Iterable, Sequence
from typing import Literal
from .typing import ColorType

class ClabelText(Text): ...

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove this line instead.

Suggested change


class ContourLabeler:
labelFmt: str | Formatter | Callable[[float], str] | dict[float, str]
Expand All @@ -41,15 +41,8 @@ class ContourLabeler:
rightside_up: bool = ...,
zorder: float | None = ...
) -> list[Text]: ...
@property
def labelFontProps(self) -> FontProperties: ...
@property
def labelFontSizeList(self) -> list[float]: ...
@property
def labelTextsList(self) -> list[Text]: ...
def print_label(self, linecontour: ArrayLike, labelwidth: float) -> bool: ...
def too_close(self, x: float, y: float, lw: float) -> bool: ...
def set_label_props(self, label: Text, text: str, color: ColorType) -> None: ...
def get_text(
self,
lev: float,
Expand Down