はじめに
matplotlib mplot3dで作成する3Dグラフの面の色と面のエッジの色を変更して表示する方法について説明する。
コード

解説
モジュールのインポートなど
バージョン
データの生成
媒介変数的に球面のデータを作成する。
plot_surfaceによる球面の表示
plot_surfaceにより表示すると以下のようになる。ax.set_box_aspect((1,1,1))によりアスペクト比を揃えている。

面の色を変えて表示
x軸側の面の色はax.xaxis.pane.set_facecolor()で変更できる。y,z軸側はxaxisの部分をそれぞれ、yaxis、zaxisに変える。
同様に面のエッジの色はax.xaxis.pane.set_edgecolor()などで変更できる。

軸目盛を非表示にする
各軸に対して、set_major_locator(ticker.NullLocator())などを設定することで軸を非表示にできる。

軸線を非表示にする
3d plotではspineの設定はできなかったので、ax.xaxis.line.set_color((1.0, 1.0, 1.0, 0.0))のようにして、RGBA形式で透明な色を設定することで見えなくしている。

参考
mpl_toolkits.mplot3d.axes3d.Axes3D — Matplotlib 3.5.0 documentation
コメント