4

matplotlib で 3 次元プロットをプロットしようとしています。単一の 3D プロットで 4 つ (または複数) の半径の周波数と振幅の分布をプロットする必要があります。私は matplotlib.collections で利用可能な PolyCollection コマンドを見ていて、例も調べましたが、既存のデータを使用してプロットに到達する方法がわかりません。

私が持っている量の次元は、

周波数:4000×4、振幅:4000×4、半径:4

私は次のようなものをプロットしたいと思います、 ここに画像の説明を入力

X 軸は周波数、Y 軸は半径、Z 軸は振幅です。この問題を解決するにはどうすればよいですか?

4

1 に答える 1

6

PolyCollection は、目的のデータと非常によく一致する一連の頂点を想定しています。サンプルデータを提供していないので、説明のためにいくつかを作成します(私の次元200はあなたの4000になります....データポイントが非常に多い場合は、これとは異なるプロットを検討するかもしれません):

import matplotlib.pyplot as plt
from matplotlib.collections import PolyCollection
from mpl_toolkits.mplot3d import axes3d
import numpy as np

# These will be (200, 4), (200, 4), and (4)
freq_data = np.linspace(0,300,200)[:,None] * np.ones(4)[None,:]
amp_data = np.random.rand(200*4).reshape((200,4))
rad_data = np.linspace(0,2,4)

verts = []
for irad in range(len(rad_data)):
    # I'm adding a zero amplitude at the beginning and the end to get a nice
    # flat bottom on the polygons
    xs = np.concatenate([[freq_data[0,irad]], freq_data[:,irad], [freq_data[-1,irad]]])
    ys = np.concatenate([[0],amp_data[:,irad],[0]])
    verts.append(list(zip(xs, ys)))

poly = PolyCollection(verts, facecolors = ['r', 'g', 'c', 'y'])
poly.set_alpha(0.7)

fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')

# The zdir keyword makes it plot the "z" vertex dimension (radius)
# along the y axis. The zs keyword sets each polygon at the
# correct radius value.
ax.add_collection3d(poly, zs=rad_data, zdir='y')

ax.set_xlim3d(freq_data.min(), freq_data.max())
ax.set_xlabel('Frequency')
ax.set_ylim3d(rad_data.min(), rad_data.max())
ax.set_ylabel('Radius')
ax.set_zlim3d(amp_data.min(), amp_data.max())
ax.set_zlabel('Amplitude')

plt.show()

これのほとんどは、あなたが言及した例から直接のものです。特定のデータセットがどこにあるのかを明確にしただけです。これにより、次のプロットが得られます。 PolyCollection プロットの例

于 2015-07-02T17:54:55.523 に答える