2016-05-13 8 views
0

私は、元のスクリプトと比較すると、わずか数新ラインここhttp://matplotlib.org/examples/mplot3d/2dcollections3d_demo.htmlmatplotlibのをpcolorの

from mpl_toolkits.mplot3d import Axes3D 
import numpy as np 
import matplotlib.pyplot as plt 

fig = plt.figure() 
ax = fig.gca(projection='3d') 

x = np.linspace(0, 1, 100) 
y = np.sin(x * 2 * np.pi)/2 + 0.5 
ax.plot(x, y, zs=0, zdir='z', label='zs=0, zdir=z') 

colors = ('r', 'g', 'b', 'k') 
for c in colors: 
    x = np.random.sample(20) 
    y = np.random.sample(20) 
    ax.scatter(x, y, 0, zdir='y', c=c) 

xc = np.linspace(0, 1, 100) 
yc = np.linspace(0, 1, 100) 
fc = np.random.random((len(xc),len(yc))) 
ax.pcolor(xc,yc,fc, zdir = 'x') 

ax.legend() 
ax.set_xlim3d(0, 1) 
ax.set_ylim3d(0, 1) 
ax.set_zlim3d(0, 1) 

plt.show() 

を与えられたコード例にpcolorのプロットを追加しようとしています。残念ながら、それはうまく終わらないし、なぜ私は本当になぜ理解していない。

Traceback (most recent call last): 
    File "/opt/local/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/matplotlib/artist.py", line 61, in draw_wrapper 
    draw(artist, renderer, *args, **kwargs) 
    File "/opt/local/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/matplotlib/figure.py", line 1159, in draw 
    func(*args) 
    File "/opt/local/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/mpl_toolkits/mplot3d/axes3d.py", line 271, in draw 
    for col in self.collections] 
    File "/opt/local/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/mpl_toolkits/mplot3d/axes3d.py", line 271, in <listcomp> 
    for col in self.collections] 
AttributeError: 'PolyCollection' object has no attribute 'do_3d_projection' 

ありがとうございます。

答えて

0

達成したいことは明確ではありません。この例では3Dプロットがありますが、pcolorは2Dプロットです。あなたがエラーを取得する理由です、3Dプロットにpcolorプロットを追加しますので、新しい数字を追加することはできません。

fig = plt.figure() 
ax = fig.gca(projection='3d') 

x = np.linspace(0, 1, 100) 
y = np.sin(x * 2 * np.pi)/2 + 0.5 
ax.plot(x, y, zs=0, zdir='z', label='zs=0, zdir=z') 

colors = ('r', 'g', 'b', 'k') 
for c in colors: 
    x = np.random.sample(20) 
    y = np.random.sample(20) 
    ax.scatter(x, y, 0, zdir='y', c=c) 

ax.legend() 
ax.set_xlim3d(0, 1) 
ax.set_ylim3d(0, 1) 
ax.set_zlim3d(0, 1) 


fig = plt.figure() 
xc = np.linspace(0, 1, 100) 
yc = np.linspace(0, 1, 100) 
fc = np.random.random((len(xc),len(yc))) 
plt.pcolor(xc,yc,fc,cmap='RdBu') 
plt.colorbar() 

pcolorには属性zdirを持っていないので、あなたはでxc,yc,fcの順序を調整する必要がありますあなたが実際に見たいものに応じて、正しい道を選びます。

+0

寄稿いただきありがとうございますが、これは私が探しているものではありません。私はよりよく説明します。サンプルスクリプトをmatplotlibウェブサイトから試してみると、ax.plotとax.scatterが3次元座標面に投影としてプロットされていることがわかります。私もax.pcolorのためにこれをやりたいと思います(あなたのような新しい人物ではありません)。 –

関連する問題