|
31 | 31 | # per level.
|
32 | 32 |
|
33 | 33 |
|
| 34 | +@_api.deprecated("3.7", alternative="Text.set_transform_rotates_text") |
34 | 35 | class ClabelText(Text):
|
35 | 36 | """
|
36 | 37 | Unlike the ordinary text, the get_rotation returns an updated
|
@@ -150,10 +151,8 @@ def clabel(self, levels=None, *,
|
150 | 151 | or minus 90 degrees from level.
|
151 | 152 |
|
152 | 153 | use_clabeltext : bool, default: False
|
153 |
| - If ``True``, `.ClabelText` class (instead of `.Text`) is used to |
154 |
| - create labels. `ClabelText` recalculates rotation angles |
155 |
| - of texts during the drawing time, therefore this can be used if |
156 |
| - aspect of the axes changes. |
| 154 | + If ``True``, use `.Text.set_transform_rotates_text` to ensure that |
| 155 | + label rotation is updated whenever the axes aspect changes. |
157 | 156 |
|
158 | 157 | zorder : float or None, default: ``(2 + contour.get_zorder())``
|
159 | 158 | zorder of the contour labels.
|
@@ -272,6 +271,7 @@ def get_label_width(self, lev, fmt, fsize):
|
272 | 271 | width *= 72 / fig.dpi
|
273 | 272 | return width
|
274 | 273 |
|
| 274 | + @_api.deprecated("3.7", alternative="Artist.set") |
275 | 275 | def set_label_props(self, label, text, color):
|
276 | 276 | """Set the label properties - color, fontsize, text."""
|
277 | 277 | label.set_text(text)
|
@@ -416,56 +416,32 @@ def calc_label_rot_and_inline(self, slc, ind, lw, lc=None, spacing=5):
|
416 | 416 |
|
417 | 417 | return rotation, nlc
|
418 | 418 |
|
419 |
| - def _get_label_text(self, x, y, rotation): |
420 |
| - dx, dy = self.axes.transData.inverted().transform((x, y)) |
421 |
| - return Text(dx, dy, rotation=rotation, |
422 |
| - horizontalalignment='center', |
423 |
| - verticalalignment='center', zorder=self._clabel_zorder) |
424 |
| - |
425 |
| - def _get_label_clabeltext(self, x, y, rotation): |
426 |
| - # x, y, rotation is given in pixel coordinate. Convert them to |
427 |
| - # the data coordinate and create a label using ClabelText |
428 |
| - # class. This way, the rotation of the clabel is along the |
429 |
| - # contour line always. |
430 |
| - transDataInv = self.axes.transData.inverted() |
431 |
| - dx, dy = transDataInv.transform((x, y)) |
432 |
| - drotation = transDataInv.transform_angles(np.array([rotation]), |
433 |
| - np.array([[x, y]])) |
434 |
| - t = ClabelText(dx, dy, rotation=drotation[0], |
435 |
| - horizontalalignment='center', |
436 |
| - verticalalignment='center', zorder=self._clabel_zorder) |
437 |
| - |
438 |
| - return t |
439 |
| - |
440 |
| - def _add_label(self, t, x, y, lev, cvalue): |
441 |
| - color = self.labelMappable.to_rgba(cvalue, alpha=self.alpha) |
442 |
| - |
443 |
| - _text = self.get_text(lev, self.labelFmt) |
444 |
| - self.set_label_props(t, _text, color) |
| 419 | + def add_label(self, x, y, rotation, lev, cvalue): |
| 420 | + """Add contour label without `.Text.set_transform_rotates_text`.""" |
| 421 | + data_x, data_y = self.axes.transData.inverted().transform((x, y)) |
| 422 | + t = Text( |
| 423 | + data_x, data_y, |
| 424 | + text=self.get_text(lev, self.labelFmt), |
| 425 | + rotation=rotation, |
| 426 | + horizontalalignment='center', verticalalignment='center', |
| 427 | + zorder=self._clabel_zorder, |
| 428 | + color=self.labelMappable.to_rgba(cvalue, alpha=self.alpha), |
| 429 | + fontproperties=self.labelFontProps, |
| 430 | + clip_box=self.axes.bbox) |
445 | 431 | self.labelTexts.append(t)
|
446 | 432 | self.labelCValues.append(cvalue)
|
447 | 433 | self.labelXYs.append((x, y))
|
448 |
| - |
449 | 434 | # Add label to plot here - useful for manual mode label selection
|
450 | 435 | self.axes.add_artist(t)
|
451 | 436 |
|
452 |
| - def add_label(self, x, y, rotation, lev, cvalue): |
453 |
| - """ |
454 |
| - Add contour label using :class:`~matplotlib.text.Text` class. |
455 |
| - """ |
456 |
| - t = self._get_label_text(x, y, rotation) |
457 |
| - self._add_label(t, x, y, lev, cvalue) |
458 |
| - |
459 | 437 | def add_label_clabeltext(self, x, y, rotation, lev, cvalue):
|
460 |
| - """ |
461 |
| - Add contour label using :class:`ClabelText` class. |
462 |
| - """ |
463 |
| - # x, y, rotation is given in pixel coordinate. Convert them to |
464 |
| - # the data coordinate and create a label using ClabelText |
465 |
| - # class. This way, the rotation of the clabel is along the |
466 |
| - # contour line always. |
467 |
| - t = self._get_label_clabeltext(x, y, rotation) |
468 |
| - self._add_label(t, x, y, lev, cvalue) |
| 438 | + """Add contour label with `.Text.set_transform_rotates_text`.""" |
| 439 | + self.add_label(x, y, rotation, lev, cvalue) |
| 440 | + # Grab the last added text, and reconfigure its rotation. |
| 441 | + t = self.labelTexts[-1] |
| 442 | + data_rotation, = self.axes.transData.inverted().transform_angles( |
| 443 | + [rotation], [[x, y]]) |
| 444 | + t.set(rotation=data_rotation, transform_rotates_text=True) |
469 | 445 |
|
470 | 446 | def add_label_near(self, x, y, inline=True, inline_spacing=5,
|
471 | 447 | transform=None):
|
|
0 commit comments