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

Skip to content

Backport PR #13548 on branch v3.1.x (Deprecate TextWithDash.) #13557

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
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/2019-03-01-AL.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Deprecations
````````````

The ``text.TextWithDash`` class and the ``withdash`` keyword argument to
``text()`` is deprecated. Consider using ``annotate()`` instead.
6 changes: 6 additions & 0 deletions examples/text_labels_and_annotations/dashpointlabel.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,13 @@
===============

"""

import warnings

import matplotlib.pyplot as plt

warnings.simplefilter("ignore") # Ignore deprecation of withdash.

DATA = ((1, 3),
(2, 4),
(3, 1),
Expand Down Expand Up @@ -36,5 +41,6 @@

ax.set_xlim((0, 5))
ax.set_ylim((0, 5))
ax.set(title="NOTE: The withdash parameter is deprecated.")

plt.show()
4 changes: 3 additions & 1 deletion lib/matplotlib/axes/_axes.py
Original file line number Diff line number Diff line change
Expand Up @@ -673,6 +673,7 @@ def secondary_yaxis(self, location, *, functions=None, **kwargs):
raise ValueError('secondary_yaxis location must be either '
'a float or "left"/"right"')

@cbook._delete_parameter("3.1", "withdash")
def text(self, x, y, s, fontdict=None, withdash=False, **kwargs):
"""
Add text to the axes.
Expand Down Expand Up @@ -748,7 +749,8 @@ def text(self, x, y, s, fontdict=None, withdash=False, **kwargs):
# the withdash kwarg and simply delegate whether there's
# a dash to TextWithDash and dashlength.

if withdash:
if (withdash
and withdash is not cbook.deprecation._deprecated_parameter):
t = mtext.TextWithDash(x, y, text=s)
else:
t = mtext.Text(x, y, text=s)
Expand Down
1 change: 1 addition & 0 deletions lib/matplotlib/figure.py
Original file line number Diff line number Diff line change
Expand Up @@ -1804,6 +1804,7 @@ def legend(self, *args, **kwargs):
self.stale = True
return l

@cbook._delete_parameter("3.1", "withdash")
@docstring.dedent_interpd
def text(self, x, y, s, fontdict=None, withdash=False, **kwargs):
"""
Expand Down
4 changes: 3 additions & 1 deletion lib/matplotlib/pyplot.py
Original file line number Diff line number Diff line change
Expand Up @@ -2936,7 +2936,9 @@ def table(

# Autogenerated by boilerplate.py. Do not edit as changes will be lost.
@docstring.copy(Axes.text)
def text(x, y, s, fontdict=None, withdash=False, **kwargs):
def text(
x, y, s, fontdict=None,
withdash=cbook.deprecation._deprecated_parameter, **kwargs):
return gca().text(x, y, s, fontdict=fontdict, withdash=withdash, **kwargs)


Expand Down
1 change: 1 addition & 0 deletions lib/matplotlib/text.py
Original file line number Diff line number Diff line change
Expand Up @@ -1245,6 +1245,7 @@ def set_fontname(self, fontname):
docstring.dedent_interpd(Text.__init__)


@cbook.deprecated("3.1", alternative="Annotation")
class TextWithDash(Text):
"""
This is basically a :class:`~matplotlib.text.Text` with a dash
Expand Down