|
|
|||||||||||||||||||||||||||||
|
matplotlib units_Examples 91_bar_demo2. |
H.Kamifuji . |
さまざまなセンチメートルとインチの変換を使用するプロット。 この例では、デフォルトのユニットイントロスペクション(ax1)、さまざまなキーワードを使用して x と y の単位をデフォルト(ax2、ax3、ax4)をオーバーライドするように設定する方法と、スカラーを使用して xlimits を設定する方法 想定)または単位(現在の単位に数値を取得するために適用される変換)。""" =================== Bar demo with units =================== A plot using a variety of centimetre and inch conversions. This example shows how default unit introspection works (ax1), how various keywords can be used to set the x and y units to override the defaults (ax2, ax3, ax4) and how one can set the xlimits using scalars (ax3, current units assumed) or units (conversions applied to get the numbers to current units). """ import numpy as np from basic_units import cm, inch import matplotlib.pyplot as plt cms = cm * np.arange(0, 10, 2) bottom = 0 * cm width = 0.8 * cm fig, axs = plt.subplots(2, 2) axs[0, 0].bar(cms, cms, bottom=bottom) axs[0, 1].bar(cms, cms, bottom=bottom, width=width, xunits=cm, yunits=inch) axs[1, 0].bar(cms, cms, bottom=bottom, width=width, xunits=inch, yunits=cm) axs[1, 0].set_xlim(2, 6) # scalars are interpreted in current units axs[1, 1].bar(cms, cms, bottom=bottom, width=width, xunits=inch, yunits=inch) axs[1, 1].set_xlim(2 * cm, 6 * cm) # cm are converted to inches fig.tight_layout() plt.show() |
このサンプルを実行するときに、basic_units_org.py が必要です。取り敢えず、実行時のカレント・ディレクトリに置けば動作します。![]() Python 3.11.2 見直しました。上記のコードでは、下記のエラーが発生します。 bar_demo2.txt matplotlib 内部のエラーのようです。matplotlib の改修(先祖帰りバグの改修)を待つしかない。 Python 3.11.6 (matplotlib 3.7.1) では、下記のようなエラーがあり、実行できない。
Traceback (most recent call last):
File "C:\Users\kamif\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:\______\bar_demo2.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:\______\bar_demo2.py", line 23, in
Python 3.11.6 (matplotlib 3.7.1) 及び Python 3.12.0 (matplotlib 3.8.1) で、見直し中、新しいサンプル(units-bar-demo2-py) を見つけ、下記のコードで、正常に実行できました。""" =================== Bar demo with units =================== A plot using a variety of centimetre and inch conversions. This example shows how default unit introspection works (ax1), how various keywords can be used to set the x and y units to override the defaults (ax2, ax3, ax4) and how one can set the xlimits using scalars (ax3, current units assumed) or units (conversions applied to get the numbers to current units). .. 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 を新しいのに、入れ替えると、元の bar_demo2.py でも、正常に実行できます。 ![]() |
|
units_Examples code: bar_demo2.py units-bar-demo2-py |
|