はじめに
3D円グラフは使うべきではない図だが、matplotlib mplot3dにより3D円グラフを表示する方法について解説する。
コード

解説
matplotlibにおける3D円グラフについて
matplotlibには3D円グラフを作成する機能はない。そのため、Wedgeを手動で3Dグラフに貼り付けることで3D円グラフを作成した。
データの生成
データは下記と同様にオリジナルサボテン用土の配合比となっている。

[matplotlib] 30. みやすい円グラフ
matplotlibで視認性の高い円グラフを作成する方法
Wedgeの角度を直接設定する必要があるので、データの合計が360になるようにする。
円グラフの設定
中心(0.5, 0.5)、半径0.5の円グラフとする。set2はQualitative colormapsであり、0から5番目までの色を選択した。
color example code: colormaps_reference.py — Matplotlib 2.0.2 documentation
Wedgeでは、中心(center)、半径(r)、開始角(theta1)、終了角(theta2)と色(color)を設定する。
3D円グラフの表示
最初にax.add_patch(w1)で3DグラフにWedgeを入れる。
次に、art3d.pathpatch_2d_to_3d(w1, z=0, zdir=”z”)により、z=0のxy平面にWedgeを置いていく。
ax.axis(“off”)で3Dグラフの軸を非表示としている。
軸を表示すると下のようになる。

参考
https://oku.edu.mie-u.ac.jp/~okumura/blog/node/2266

[matplotlib] 30. みやすい円グラフ
matplotlibで視認性の高い円グラフを作成する方法

[matplotlib 3D] 11. 3Dグラフ上に円、線、面などの図形を表示(pathpatch3d)
3Dグラフ上に円、線、面などの図形を表示する方法について説明する。
matplotlib.patches.Wedge — Matplotlib 3.1.2 documentation
Draw flat objects in 3D plot — Matplotlib 3.1.0 documentation
コメント