|

2026/08/18 改修追記
Windows Python 3.14.6 (matplotlib 3.11.1) では、下記のようなエラーがあり、実行できない。
Traceback (most recent call last):
File "D:___\dashpointlabel.py", line 26, in
t = ax.text(x, y, str((x, y)), withdash=True,
dashdirection=dd,
...<3 lines>...
dashpush=dp,
)
File "C:___\AppData\Local\Python\pythoncore-3.14-64\
Lib\site-packages\matplotlib\axes\_axes.py", line 725, in text
t = mtext.Text(x, y, text=s, **effective_kwargs)
File "C:___\AppData\Local\Python\pythoncore-3.14-64\
Lib\site-packages\matplotlib\text.py", line 211, in __init__
self.update(kwargs)
~~~~~~~~~~~^^^^^^^^
File "C:___\AppData\Local\Python\pythoncore-3.14-64\
Lib\site-packages\matplotlib\text.py", line 260, in update
ret.extend(super().update(kwargs))
~~~~~~~~~~~~~~^^^^^^^^
File "C:___\AppData\Local\Python\pythoncore-3.14-64\
Lib\site-packages\matplotlib\artist.py", line 1303, in update
return self._update_props(
~~~~~~~~~~~~~~~~~~^
props, "{cls.__name__!r} object has no property {prop_name!r}")
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:___\AppData\Local\Python\pythoncore-3.14-64\
Lib\site-packages\matplotlib\artist.py", line 1271, in _update_props
raise AttributeError(
errfmt.format(cls=type(self), prop_name=k),
name=k)
AttributeError: 'Text' object has no property 'withdash'
Linux Python3 3.8.6 (matplotlib 3.3.3) では、下記のようなエラーがあり、実行できない。
Traceback (most recent call last):
File "dashpointlabel.py", line 31, in
dashpush=dp,
File "/home/wwwadmin/.local/lib/python3.6/site-packages/matplotlib/axes/_axes.py", line 765, in text
t = mtext.Text(x, y, text=s, **effective_kwargs)
File "/home/wwwadmin/.local/lib/python3.6/site-packages/matplotlib/text.py", line 166, in __init__
self.update(kwargs)
File "/home/wwwadmin/.local/lib/python3.6/site-packages/matplotlib/text.py", line 179, in update
super().update(kwargs)
File "/home/wwwadmin/.local/lib/python3.6/site-packages/matplotlib/artist.py", line 996, in update
raise AttributeError(f"{type(self).__name__!r} object "
AttributeError: 'Text' object has no property 'withdash'
Python 3.11.2 見直しました。上記のコードでは、下記のエラーが発生します。
Traceback (most recent call last):
File "_:\dashpointlabel.py", line 26, in <module>
t = ax.text(x, y, str((x, y)), withdash=True,
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\_____\AppData\Local\Programs\Python\Python311\Lib\site-packages\matplotlib\axes\_axes.py", line 689, in text
t = mtext.Text(x, y, text=s, **effective_kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\_____\AppData\Local\Programs\Python\Python311\Lib\site-packages\matplotlib\_api\deprecation.py", line 454, in wrapper
return func(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\_____\AppData\Local\Programs\Python\Python311\Lib\site-packages\matplotlib\text.py", line 183, in __init__
self.update(kwargs)
File "C:\Users\_____\AppData\Local\Programs\Python\Python311\Lib\site-packages\matplotlib\text.py", line 231, in update
super().update(kwargs)
File "C:\Users\_____\AppData\Local\Programs\Python\Python311\Lib\site-packages\matplotlib\artist.py", line 1213, in update
return self._update_props(
^^^^^^^^^^^^^^^^^^^
File "C:\Users\_____\AppData\Local\Programs\Python\Python311\Lib\site-packages\matplotlib\artist.py", line 1197, in _update_props
raise AttributeError(
AttributeError: 'Text' object has no property 'withdash'
matplotlib 内部のエラーのようです。matplotlib の改修(先祖帰りバグの改修)を待つしかない。
Python 3.11.6 (matplotlib 3.7.1) では、下記のようなエラーがあり、実行できない。
Traceback (most recent call last):
File "M:\______\dashpointlabel.py", line 26, in
t = ax.text(x, y, str((x, y)), withdash=True,
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\______\AppData\Local\Programs\Python\Python311\Lib
\site-packages\matplotlib\axes\_axes.py", line 689, in text
t = mtext.Text(x, y, text=s, **effective_kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\______\AppData\Local\Programs\Python\Python311\Lib
\site-packages\matplotlib\_api\deprecation.py", line 454, in wrapper
return func(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\______\AppData\Local\Programs\Python\Python311\Lib
\site-packages\matplotlib\text.py", line 183, in __init__
self.update(kwargs)
File "C:\Users\______\AppData\Local\Programs\Python\Python311\Lib
\site-packages\matplotlib\text.py", line 231, in update
super().update(kwargs)
File "C:\Users\______\AppData\Local\Programs\Python\Python311\Lib
\site-packages\matplotlib\artist.py", line 1213, in update
return self._update_props(
^^^^^^^^^^^^^^^^^^^
File "C:\Users\______\AppData\Local\Programs\Python\Python311\Lib
\site-packages\matplotlib\artist.py", line 1197, in _update_props
raise AttributeError(
AttributeError: 'Text' object has no property 'withdash'
Python 3.12.0 (matplotlib 3.8.1) では、下記のようなエラーがあり、実行できない。
Traceback (most recent call last):
File "E:\______\dashpointlabel.py", line 26, in
t = ax.text(x, y, str((x, y)), withdash=True,
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Program Files\Python312\Lib\site-packages\matplotlib\axes\_axes.py",
line 700, in text
t = mtext.Text(x, y, text=s, **effective_kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Program Files\Python312\Lib\site-packages\matplotlib\text.py",
line 155, in __init__
self.update(kwargs)
File "C:\Program Files\Python312\Lib\site-packages\matplotlib\text.py",
line 205, in update
ret.extend(super().update(kwargs))
^^^^^^^^^^^^^^^^^^^^^^
File "C:\Program Files\Python312\Lib\site-packages\matplotlib\artist.py",
line 1209, in update
return self._update_props(
^^^^^^^^^^^^^^^^^^^
File "C:\Program Files\Python312\Lib\site-packages\matplotlib\artist.py",
line 1193, in _update_props
raise AttributeError(
AttributeError: 'Text' object has no property 'withdash'
Python 3.11.6 (matplotlib 3.7.1) 及び Python 3.12.0 (matplotlib 3.8.1) では、withdash 機能が削除されたようです。代替サンプルも見つからないので、dash が未完ながら、文字列の配置と回転を試みました。
# Fixed by H.Kamifuji 2023/11/24
#
import matplotlib.pyplot as plt
DATA = ((1, 3),
(2, 4),
(3, 1),
(4, 2))
# dash_style =
# direction, length, (text)rotation, dashrotation, push
# (The parameters are varied to show their effects,
# not for visual appeal).
dash_style = (
(0, 20, -15, -0.60, -0.30),
(1, 30, 0, 0.60, 0.30),
(0, 40, 15, -0.60, -0.30),
(1, 20, 30, 0.30, 0.60),
)
fig, ax = plt.subplots()
(x, y) = zip(*DATA)
ax.plot(x, y, marker='o')
for i in range(len(DATA)):
(x, y) = DATA[i]
(dd, dl, r, dr, dp) = dash_style[i]
#print('dashlen call %d' % dl)
t = ax.text(x + dr, y + dp, str((x, y)),
rotation=r,
horizontalalignment='center',
verticalalignment='center',
)
ax.set_xlim((0.0, 5.0))
ax.set_ylim((0.0, 5.0))
plt.show()
Python 3.11.6 (matplotlib 3.7.1) 及び Python 3.12.0 (matplotlib 3.8.1) 共に、正常実行です。

Windows Python 3.14.6 (matplotlib 3.11.1) では、正常に、実行できる。
Linux Python3 3.8.6 (matplotlib 3.3.3) では、正常に、実行できる。
|