|
|
|||||||||||||||||||||||||||||
|
matplotlib units_Examples 89_annotate_with_units. |
H.Kamifuji . |
|
ユニットによる注釈 この例では、センチメートルスケールのプロットを使用してテキストと矢印の注釈を作成する方法を示しています。
"""
=====================
Annotation with units
=====================
The example illustrates how to create text and arrow
annotations using a centimeter-scale plot.
"""
import matplotlib.pyplot as plt
from basic_units import cm
fig, ax = plt.subplots()
ax.annotate("Note 01", [0.5*cm, 0.5*cm])
# xy and text both unitized
ax.annotate('local max', xy=(3*cm, 1*cm), xycoords='data',
xytext=(0.8*cm, 0.95*cm), textcoords='data',
arrowprops=dict(facecolor='black', shrink=0.05),
horizontalalignment='right', verticalalignment='top')
# mixing units w/ nonunits
ax.annotate('local max', xy=(3*cm, 1*cm), xycoords='data',
xytext=(0.8, 0.95), textcoords='axes fraction',
arrowprops=dict(facecolor='black', shrink=0.05),
horizontalalignment='right', verticalalignment='top')
ax.set_xlim(0*cm, 4*cm)
ax.set_ylim(0*cm, 4*cm)
plt.show()
|
このサンプルを実行するときに、basic_units_org.py が必要です。取り敢えず、実行時のカレント・ディレクトリに置けば動作します。![]() Python 3.11.2 見直しました。上記のコードでは、下記のエラーが発生します。 annotate_with_units.txt matplotlib 内部のエラーのようです。matplotlib の改修(先祖帰りバグの改修)を待つしかない。 Python 3.11.6 (matplotlib 3.7.1) では、下記のようなエラーがあり、実行できない。
Traceback (most recent call last):
File "C:\Users\______\AppData\Local\Programs\Python\Python311\Lib
\site-packages\matplotlib\axis.py", line 1732, in convert_units
ret = self.converter.convert(x, self.units, self)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "M:\______\basic_units.py", line 341, in convert
if units.ConversionInterface.is_numlike(val):
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: type object 'ConversionInterface' has no attribute 'is_numlike'
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "M:\______\annotate_with_units.py", line 30, in
Python 3.12.0 (matplotlib 3.8.1) では、下記のようなエラーがあり、実行できない。
Traceback (most recent call last):
File "C:\Program Files\Python312\Lib\site-packages\matplotlib\axis.py",
line 1769, in convert_units
ret = self.converter.convert(x, self.units, self)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "E:\______\basic_units.py", line 341, in convert
if units.ConversionInterface.is_numlike(val):
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: type object 'ConversionInterface' has no attribute 'is_numlike'
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "E:\______\annotate_with_units.py", line 30, in
Python 3.11.6 (matplotlib 3.7.1) 及び Python 3.12.0 (matplotlib 3.8.1) で、見直し中、新しいサンプル(units-annotate-with-units-py) を見つけ、下記のコードで、正常に実行できました。""" ===================== Annotation with units ===================== The example illustrates how to create text and arrow annotations using a centimeter-scale plot. .. only:: builder_html This example requires :download:`basic_units.pyPython 3.11.6 (matplotlib 3.7.1) 及び Python 3.12.0 (matplotlib 3.8.1) 共に、正常実行です。 このサンプルを実行するときに、basic_units.py が必要です。取り敢えず、実行時のカレント・ディレクトリに置けば動作します。 ![]() |
|
units_Examples code: annotate_with_units.py units-annotate-with-units-py |
|