|
|
|||||||||||||||||||||||||||||
|
matplotlib api_Examples 33_scatter_piecharts. |
H.Kamifuji . |
|
この例では、カスタム '円グラフ' を散布図のマーカーとして使用します。 例の Manuel Metz に感謝します この事例は、Windows10_1909 で Python 3.9.0 環境では、動作しません。( \lib\site-packages\matplotlib\markers.py がデグレートしたのか? )
"""
===================================
Scatter plot with pie chart markers
===================================
This example makes custom 'pie charts' as the markers for a scatter plot.
Thanks to Manuel Metz for the example
"""
import math
import numpy as np
import matplotlib.pyplot as plt
# first define the ratios
r1 = 0.2 # 20%
r2 = r1 + 0.4 # 40%
# define some sizes of the scatter marker
sizes = [60, 80, 120]
# calculate the points of the first pie marker
#
# these are just the origin (0,0) +
# some points on a circle cos,sin
x = [0] + np.cos(np.linspace(0, 2*math.pi*r1, 10)).tolist()
y = [0] + np.sin(np.linspace(0, 2*math.pi*r1, 10)).tolist()
xy1 = list(zip(x, y))
s1 = max(max(x), max(y))
# ...
x = [0] + np.cos(np.linspace(2*math.pi*r1, 2*math.pi*r2, 10)).tolist()
y = [0] + np.sin(np.linspace(2*math.pi*r1, 2*math.pi*r2, 10)).tolist()
xy2 = list(zip(x, y))
s2 = max(max(x), max(y))
x = [0] + np.cos(np.linspace(2*math.pi*r2, 2*math.pi, 10)).tolist()
y = [0] + np.sin(np.linspace(2*math.pi*r2, 2*math.pi, 10)).tolist()
xy3 = list(zip(x, y))
s3 = max(max(x), max(y))
fig, ax = plt.subplots()
ax.scatter(np.arange(3), np.arange(3), marker=(xy1, 0),
s=[s1*s1*_ for _ in sizes], facecolor='blue')
ax.scatter(np.arange(3), np.arange(3), marker=(xy2, 0),
s=[s2*s2*_ for _ in sizes], facecolor='green')
ax.scatter(np.arange(3), np.arange(3), marker=(xy3, 0),
s=[s3*s3*_ for _ in sizes], facecolor='red')
plt.show()
|
![]() Python 3.11.2 見直しました。上記のコードでは、下記のエラーが発生します。 Traceback (most recent call last): File "_:\scatter_piecharts.py", line 43, in ax.scatter(np.arange(3), np.arange(3), marker=(xy1, 0), File "C:\Users\kamif\AppData\Local\Programs\Python\Python311\Lib\site-packages\matplotlib\__init__.py", line 1459, in inner return func(ax, *map(sanitize_sequence, args), **kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\kamif\AppData\Local\Programs\Python\Python311\Lib\site-packages\matplotlib\axes\_axes.py", line 4629, in scatter marker_obj = mmarkers.MarkerStyle(marker) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\kamif\AppData\Local\Programs\Python\Python311\Lib\site-packages\matplotlib\markers.py", line 272, in __init__ self._set_marker(marker) File "C:\Users\kamif\AppData\Local\Programs\Python\Python311\Lib\site-packages\matplotlib\markers.py", line 367, in _set_marker self._recache() File "C:\Users\kamif\AppData\Local\Programs\Python\Python311\Lib\site-packages\matplotlib\markers.py", line 291, in _recache self._marker_function() File "C:\Users\kamif\AppData\Local\Programs\Python\Python311\Lib\site-packages\matplotlib\markers.py", line 504, in _set_tuple_marker self._path = Path.unit_regular_polygon(numsides) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\kamif\AppData\Local\Programs\Python\Python311\Lib\site-packages\matplotlib\path.py", line 749, in unit_regular_polygon if numVertices <= 16: ^^^^^^^^^^^^^^^^^ TypeError: '<=' not supported between instances of 'list' and 'int' matplotlib 内部のエラーのようです。matplotlib の改修(先祖帰りバグの改修)を待つしかない。 Traceback (most recent call last): File "M:\______\scatter_piecharts.py", line 43, inPython 3.12.0 (matplotlib 3.8.1) では、下記のようなエラーがあり、実行できない。 Traceback (most recent call last): File "E:\______\scatter_piecharts.py", line 43, in現時点(2023/11/10) では、対応した新しいサンプルを見つけれない。 |
| api example code: scatter_piecharts.py |
|