はじめに
matplotlib mplot3dの3D wireframeグラフでX or Y 軸の一方向だけのデータを表示する方法について解説する。
コード
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
%matplotlib inline
import matplotlib.pyplot as plt
import numpy as np
from mpl_toolkits.mplot3d import axes3d
plt.style.use('ggplot')
plt.rcParams["axes.facecolor"] = 'white'
fig, [ax1, ax2] = plt.subplots(1, 2, figsize=(8, 4), subplot_kw={'projection': '3d'})
# Get the test data
X, Y, Z = axes3d.get_test_data(0.05)
# Give the first plot only wireframes of the type y = c
ax1.plot_wireframe(X, Y, Z, rcount=10, ccount=0)
ax1.set_title("Column (x) count set to 0")
# Give the second plot only wireframes of the type x = c
ax2.plot_wireframe(X, Y, Z, rcount=0, ccount=10)
ax2.set_title("Row (y) count set to 0")
plt.tight_layout()
plt.savefig('one_direction_3dwf.jpg',dpi=120)
plt.show()

解説
モジュールのインポート
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
%matplotlib inline
import matplotlib.pyplot as plt
import numpy as np
from mpl_toolkits.mplot3d import axes3d
図の作成
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fig, [ax1, ax2] = plt.subplots(1, 2, figsize=(8, 4), subplot_kw={'projection': '3d'})
subplot_kw={‘projection’: ‘3d’}は、add_subplot(111,projection=’3d’)とおなじ。
一方向wireframeグラフの作成
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ax1.plot_wireframe(X, Y, Z, rcount=10, ccount=0)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ax2.plot_wireframe(X, Y, Z, rcount=0, ccount=10)
ccount, rcountをそれぞれ0とすることで、その方向にデータが非表示となる。
各方向で色を変えて描写
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fig, ax = plt.subplots(figsize=(5, 5),subplot_kw={'projection': '3d'})
ax.plot_wireframe(X, Y, Z, rcount=10, ccount=0,color='m')
ax.plot_wireframe(X, Y, Z, rcount=0, ccount=10,color='g')
plt.tight_layout()
plt.savefig('one_direction_3dwf_dc.jpg',dpi=120)
plt.show()

参考
mplot3d tutorial — Matplotlib 2.0.2 documentation
mplot3d example code: wire3d_zero_stride.py — Matplotlib 2.0.2 documentation
コメント