2016-09-13 21 views
0

を無視している。これは私のプロットである:これは、表面プロットすることになっているmatplotlibのは、与えられたcolourmap

enter image description here

。あなたが見ることができるように、それは幾分失敗しました。特に、渡されたカラーマップを無視しています。

それはそうと呼び出されます:

from mpl_toolkits.mplot3d import Axes3D 
import matplotlib.pyplot as plt 
# Set global options 
plt.rc('text', usetex=True) 
plt.rc('font', family='sans-serif') 

from scipy.interpolate import griddata 
from matplotlib import cm 
import numpy as np 

class testPlot(object): 

    def __init__(self,trajDict): 
     # Concat dictionary into (n_i x D) for all i in speeds. 
     D = np.vstack(trajDict.values()) 
     # Grid the data: [time,angle,velocity] 
     # time 
     self.X = D[:,0] 
     # angle 
     self.Y = D[:,1] 
     # velocity 
     self.Z = D[:,2] 
     # All vels 
     self.vels = [1.42,1.11,0.81,0.50] 
    def surfacePlot(self,intMethod,wire=False,surface=False): 
     zi = np.linspace(self.Z.min(),self.Z.max(),250) 
     xi = np.linspace(self.X.min(),self.X.max(),250) 
     yi = griddata((self.X, self.Z), 
         self.Y, 
         (xi[None,:], zi[:,None]), 
         method=intMethod) 

     fig = plt.figure(figsize=(10,10)) 
     ax = fig.add_subplot(111, projection='3d') #fig.gca(projection='3d') 
     zig, xig = np.meshgrid(xi, zi) 
     if surface: 
      surf = ax.plot_surface(zig, xig, yi, 
            cmap='Blues', 
            alpha=0.5) 

     ax.grid(False) 
     ax.set_ylabel('Velocity $[m/s]$') 
     ax.set_ylim([min(self.vels)-0.2, max(self.vels)+0.2]) 
     ax.set_axis_off 
     ax.set_zlabel('Angle $[\circ]$') 
     ax.set_zlim([min(self.Y)-5,max(self.Y)+5]) 
     ax.set_xlabel('Gait Cycle $[\%]$') 
     ax.set_xlim([self.X[0]-10,self.X[-1]])  
     plt.gca().invert_yaxis() 
     plt.show() 
     # Close existing windows 
     plt.close(fig) 

は、テストのために、このMWEデータを渡す:

OrderedDict([('a', array([[ 0. , 0. , 1.42], 
        [ 1. , 1. , 1.42], 
        [ 2. , 2. , 1.42], 
        [ 3. , 3. , 1.42], 
        [ 4. , 4. , 1.42]])), 
      ('b', array([[ 0. , 1. , 1.11], 
        [ 1. , 2. , 1.11], 
        [ 2. , 3. , 1.11], 
        [ 3. , 4. , 1.11], 
        [ 4. , 5. , 1.11]])), 
      ('c', array([[ 0. , 4. , 0.81], 
        [ 1. , 5. , 0.81], 
        [ 2. , 6. , 0.81], 
        [ 3. , 7. , 0.81], 
        [ 4. , 8. , 0.81]])), 
      ('d', array([[ 0. , 9. , 0.5], 
        [ 1. , 10. , 0.5], 
        [ 2. , 11. , 0.5], 
        [ 3. , 12. , 0.5], 
        [ 4. , 13. , 0.5]]))]) 

myTest = testPlot(data) 
myTest.surfacePlot('linear',surface=True) 

に(注作業MWEを与える必要があります:それはないだろう上記のプロットを再現する)。データは上記の形式で動作する必要があることに注意してください。

+0

プロットは、面図の代わりにワイヤフレームのように見えます。実際に 'plot_wireframe'ではなく' plot_surface'を呼び出しているか確認してください。 'plot_surface'からオプションの引数をすべて削除しようとしましたか?また、 'matplotlib import cm'から' cm.Blues'を使ってみましたか? –

+0

また、 'plt.gca()'を 'ax'だけで置き換えることができると思います。 –

+0

@NilsWernerあなたの提案に感謝します。私は両方を試みたし、どちらもうまくいっていないと言いました。私はまた、ワイヤフレームオプションをコメントアウトしたので、ワイヤフレームをプロットするべきではありません。 – Astrid

答えて

0

コードは問題なく、表示されるプロットはサーフェスプロットです。背景の線は青みがかった部分の後ろにあるので、あなたに伝えることができます。アルファ設定を削除するか、別のcmapを使用するか、データ範囲に合わせてカラーバーのカスタム範囲を指定してください。

関連する問題