|
|
|||||||||||||||||||||||||||||
|
matplotlib units_Examples 92_bar_unit_demo. |
H.Kamifuji . |
|
グループを持つユニット これは、下記のページを参照 the barchart demo(センチメートル)
"""
=========================
Group barchart with units
=========================
This is the same example as
<a href='http://matplotlib.org/examples/api/barchart_demo.html'>
the barchart demo</a> in centimeters.
"""
import numpy as np
from basic_units import cm, inch
import matplotlib.pyplot as plt
N = 5
menMeans = (150*cm, 160*cm, 146*cm, 172*cm, 155*cm)
menStd = (20*cm, 30*cm, 32*cm, 10*cm, 20*cm)
fig, ax = plt.subplots()
ind = np.arange(N) # the x locations for the groups
width = 0.35 # the width of the bars
p1 = ax.bar(ind, menMeans, width, color='r', bottom=0*cm, yerr=menStd)
womenMeans = (145*cm, 149*cm, 172*cm, 165*cm, 200*cm)
womenStd = (30*cm, 25*cm, 20*cm, 31*cm, 22*cm)
p2 = ax.bar(ind + width, womenMeans, width,
color='y', bottom=0*cm, yerr=womenStd)
ax.set_title('Scores by group and gender')
ax.set_xticks(ind + width / 2)
ax.set_xticklabels(('G1', 'G2', 'G3', 'G4', 'G5'))
ax.legend((p1[0], p2[0]), ('Men', 'Women'))
ax.yaxis.set_units(inch)
ax.autoscale_view()
plt.show()
|
このサンプルを実行するときに、basic_units_org.py が必要です。取り敢えず、実行時のカレント・ディレクトリに置けば動作します。![]() Python 3.11.2 見直しました。上記のコードでは、下記のエラーが発生します。 bar_unit_demo.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:\______\bar_unit_demo.py", line 24, 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_unit_demo.py", line 24, in
Python 3.11.6 (matplotlib 3.7.1) 及び Python 3.12.0 (matplotlib 3.8.1) で、見直し中、新しいサンプル(units-bar-unit-demo-py) を見つけ、下記のコードで、正常に実行できました。""" ========================= Group barchart with units ========================= This is the same example as :doc:`the barchart</gallery/lines_bars_and_markers/barchart>` in centimeters. .. 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_unit_demo.py でも、正常に実行できます。 ![]() |
|
units_Examples code: bar_unit_demo.py units-bar-unit-demo-py |
|