|
|
|||||||||||||||||||||||||||||
|
matplotlib units_Examples 98_units_scatter. |
H.Kamifuji . |
|
basic_units は、目的のテストに使用される真のユニットパッケージのモックアップであり、unit パッケージが matplotlib に提供しなければならない基本的なインターフェースを示しています。 以下の例は、マスクされた配列の単位変換のサポートを示しています。 """ ============= Unit handling ============= basic_units is a mockup of a true units package used for testing purposed, which illustrates the basic interface that a units package must provide to matplotlib. The example below shows support for unit conversions over masked arrays. """ import numpy as np import matplotlib.pyplot as plt from basic_units import secs, hertz, minutes # create masked array data = (1, 2, 3, 4, 5, 6, 7, 8) mask = (1, 0, 1, 0, 0, 0, 1, 0) xsecs = secs * np.ma.MaskedArray(data, mask, float) fig, (ax1, ax2, ax3) = plt.subplots(nrows=3, sharex=True) ax1.scatter(xsecs, xsecs) ax1.yaxis.set_units(secs) ax1.axis([0, 10, 0, 10]) ax2.scatter(xsecs, xsecs, yunits=hertz) ax2.axis([0, 10, 0, 1]) ax3.scatter(xsecs, xsecs, yunits=hertz) ax3.yaxis.set_units(minutes) ax3.axis([0, 10, 0, 1]) fig.tight_layout() plt.show() |
![]() Python 3.11.2 見直しました。上記のコードでは、下記のエラーが発生します。 units_scatter.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:\______\units_scatter.py", line 23, 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:\______\units_scatter.py", line 23, in
Python 3.11.6 (matplotlib 3.7.1) 及び Python 3.12.0 (matplotlib 3.8.1) で、見直し中、新しいサンプル(units-units-scatter-py) を見つけ、下記のコードで、正常に実行できました。""" ============= Unit handling ============= The example below shows support for unit conversions over masked arrays. .. 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 が必要です。取り敢えず、実行時のカレント・ディレクトリに置けば動作します。 ![]() basic_units.py を新しいのに、入れ替えると、元の units_scatter.py でも、正常に実行できます。 ![]() |
|
units_Examples code: units_scatter.py units-units-scatter-py |
|