|
|
|||||||||||||||||||||||||||||
|
matplotlib units_Examples 97_units_sample. |
H.Kamifuji . |
この例は、 `plot` 関数の `xunits` と `yunits` パラメータを使って、デフォルトの x と y の単位(ax1)をインチとセンチメートルに上書きする機能を示しています。 数字を正しい単位に変換するために変換が適用されることに注意してください。""" ====================== Inches and Centimeters ====================== The example illustrates the ability to override default x and y units (ax1) to inches and centimeters using the `xunits` and `yunits` parameters for the `plot` function. Note that conversions are applied to get numbers to correct units. """ from basic_units import cm, inch import matplotlib.pyplot as plt import numpy cms = cm * numpy.arange(0, 10, 2) fig = plt.figure() ax1 = fig.add_subplot(2, 2, 1) ax1.plot(cms, cms) ax2 = fig.add_subplot(2, 2, 2) ax2.plot(cms, cms, xunits=cm, yunits=inch) ax3 = fig.add_subplot(2, 2, 3) ax3.plot(cms, cms, xunits=inch, yunits=cm) ax3.set_xlim(3, 6) # scalars are interpreted in current units ax4 = fig.add_subplot(2, 2, 4) ax4.plot(cms, cms, xunits=inch, yunits=inch) ax4.set_xlim(3*cm, 6*cm) # cm are converted to inches plt.show() |
このサンプルを実行するときに、basic_units_org.py が必要です。取り敢えず、実行時のカレント・ディレクトリに置けば動作します。![]() Python 3.11.2 見直しました。上記のコードでは、下記のエラーが発生します。 units_sample.txt matplotlib 内部のエラーのようです。matplotlib の改修(先祖帰りバグの改修)を待つしかない。 Python 3.11.6 (matplotlib 3.7.1) では、下記のようなエラーがあり、実行できない。 Traceback (most recent call last): File "M:\______\units_sample.py", line 21, inPython 3.12.0 (matplotlib 3.8.1) では、下記のようなエラーがあり、実行できない。 Traceback (most recent call last): File "E:\______\units_sample.py", line 21, inPython 3.11.6 (matplotlib 3.7.1) 及び Python 3.12.0 (matplotlib 3.8.1) で、見直し中、新しいサンプル( units-units-sample-py ) を見つけ、下記のコードで、正常に実行できました。 """ ====================== Inches and Centimeters ====================== The example illustrates the ability to override default x and y units (ax1) to inches and centimeters using the *xunits* and *yunits* parameters for the `~.axes.Axes.plot` function. Note that conversions are applied to get numbers to correct 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 を新しいのに、入れ替えると、元の units_sample.py でも、正常に実行できます。 ![]() |
|
units_Examples code: units_sample.py units-units-sample-py |
|