2013-02-28 48 views
9

私はz値に従ってワイヤフレームプロットの色を付けようとしています。私はインターネット上でコード例を見つけることができません。ここでmatplotlibの色付きワイヤフレームプロット

は、私が欲しい色と私はライン上の色を取得するために管理することはできませんワイヤーフレームプロットを有し、表面プロットの例である:

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

# some numbers for the data 
P=12000 #W 
Q=1  #kg/s 
DT=3 #K 
cp=4169.32 #J/kgK 

dDT=np.logspace(-2,0,20,endpoint=True) 
dQ=Q*np.logspace(-3,-1,20,endpoint=True) 

# the plotting data 
m1,m2=np.meshgrid(dDT,dQ) 
err=cp*np.sqrt((m1*Q)**2+(m2*DT)**2)/P 

# the wiremesh plot that i need fixed 
fig=plt.figure() 
ax = fig.add_subplot(111, projection='3d') 
ax.plot_wireframe(m1, m2, err, color=err/err.max(),cmap='jet') 
ax.set_xlabel('dDT') 
ax.set_ylabel('DQ') 
ax.set_zlabel('relative error') 

# the surface plot that has the colors i want 
fig = plt.figure() 
ax = fig.gca(projection='3d') 

surf = ax.plot_surface(m1, m2, err,rstride=1, cstride=1, cmap=cm.jet, 
    linewidth=0.1, antialiased=False) 

fig.colorbar(surf, shrink=0.5, aspect=5) 

ax.set_xlabel('dDT') 
ax.set_ylabel('DQ') 
ax.set_zlabel('relative error') 
plt.show() 

は、任意の助けをありがとう!

+0

http://stackoverflow.com/questions/24909256/how-to-obtain-3d-colored-surface-via-python/24958192#24958192の可能性のある重複? – GBy

答えて

6

あなたがplot_wireframeを使用する場合は、各行が一つだけの色を持つことができます。 代わりに、plot_surfaceを使用できます。 edgecolorsを設定するplot_surfaceを取得するには、それにfacecolorsを付ける必要があります。 次に、facecolorsのアルファベットをゼロに設定できます。

from mpl_toolkits.mplot3d import axes3d 
import matplotlib.pyplot as plt 
from matplotlib import cm 

X, Y, Z = axes3d.get_test_data(0.2) 

# Normalize to [0,1] 
Z = (Z-Z.min())/(Z.max()-Z.min()) 

colors = cm.viridis(Z) 
rcount, ccount, _ = colors.shape 

fig = plt.figure() 
ax = fig.gca(projection='3d') 
surf = ax.plot_surface(X, Y, Z, rcount=rcount, ccount=ccount, 
         facecolors=colors, shade=False) 
surf.set_facecolor((0,0,0,0)) 
plt.show() 

z color wireframe

1

私は、どちらもうまくいかなかった変数に従ってサークルの色付けとサイジングに同様の問題がありました。だから私の回避策は、変数の値をビンにしてビンにループすることでした。配列maskにはそのビン内の値を持つデータのみが含まれるようにデータをマスクしました。

ax.plot_wireframe(mask[i], ..., color="red") 
ax.plot_wireframe(mask[i], ..., color="blue") 
etc. 

私はそれは非常にエレガントではありません知っているが、私の場合はそれが仕事をしてくれた;)

+0

申し訳ありませんが私はそれを取得していません。あなたはコード例を投稿できますか? – user1805743

1

たぶんあなたの代わりにplot_surfaceを使用する必要がありますか?

import matplotlib.pylab as plt 
from matplotlib import cm 
from mpl_toolkits.mplot3d import Axes3D 

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

t = np.linspace(-3, 2, 31) 
s = np.linspace(-3, 2, 31) 

T, S = np.meshgrid(t, s) 

ax.plot_surface(T * T, sqrt2 * T * S, S * S, cmap=cm.jet, rstride=1, cstride=1) 

ax.set_xlabel('$t^2$') 
ax.set_ylabel('$\sqrt{2} s t$') 
ax.set_zlabel('$s^2$') 

ax.set_title('line $s = t$ in $\cal F$') 

plt.show() 

enter image description here

関連する問題