2013-02-07 32 views
3

我正在寫一段代碼,模擬原子在電場和磁場中的相互作用。其中一部分需要我在給定的高度上生成相互作用勢的3D圖。完整的代碼產生這些地塊很長,分跨多個模塊但是相關的繪圖部分是:停止從具有軸標籤的matplotlib 3D表面圖切除

# Function to plot 'PlotValues' at a height 'z' 
def Plot_AtHeight(self, PlotValues, z=500, ReturnFig=False, ShowTime=False): 

    # Calls out to the relevant function to calculate the values and return 
    # these as an array 
    PlotArray = self.Get_AtHeight(PlotValues, z) 

    pylab.rcParams.update(\ 
     {'axes.labelsize': 18, 
     'text.fontsize': 18, 
     'xtick.labelsize': 18, 
     'ytick.labelsize': 18 
     }) 

    fig = pylab.figure() 
    ax = Axes3D(fig) 

    # Make the arrays of the points at which the values are calculated 
    X, Y = np.mgrid[Xmin:Xmax:complex(0,Xpoints), 
        Ymin:Ymax:complex(0,Ypoints)] 

    ax.plot_surface(X, Y, PlotArray, cmap=cm.jet) 

    ax.set_xlabel('Position, x (nm)') 
    ax.set_ylabel('Position, y (nm)') 

    if PlotValues == 'B':   ax.set_zlabel('Field Strength (G)',   fontsize=18) 
    elif PlotValues == 'E':   ax.set_zlabel('Field Strength (V/m)',  fontsize=18) 
    elif PlotValues == 'U_Stark':  ax.set_zlabel('Stark Interaction (J)',  fontsize=18) 
    elif PlotValues == 'U_Zeeman': ax.set_zlabel('Zeeman Interaction (J)',  fontsize=18) 
    elif PlotValues == 'U':   ax.set_zlabel('Interaction Potential (J)', fontsize=18) 
    elif PlotValues == 'U_Stark_mK': ax.set_zlabel('Stark Interaction (mK)',  fontsize=18) 
    elif PlotValues == 'U_Zeeman_mK': ax.set_zlabel('Zeeman Interaction (mK)', fontsize=18) 
    elif PlotValues == 'U_mK':  ax.set_zlabel('Interaction Potential (mK)', fontsize=18) 

    # If we are not in a time averaged environment then display the current 
    # time (in ns) as the title to 1 decimal place. 
    if not self.TimeAveraged and ShowTime: 
     TimeStr = str(time*10**9) 
     try: 
      TimeTo1dp = '.'.join([TimeStr.split('.')[0], TimeStr.split('.')[1][0]]) 
     except: 
      TimeTo1dp = TimeStr 
     ax.set_title("t = %sns" % TimeTo1dp, fontsize=18) 

    if not ReturnFig: pylab.show() 
    elif ReturnFig: return fig 

這將返回該地塊的一個例子是:

one of the plots created

你可以看到軸標籤和刻度有點雜亂。特別是,我希望有人可能知道如何停止在底部切掉的圖像(即1000個圖像全部清晰)。我在很多角度都遇到了這個問題,有些時候軸標籤被切斷了,有時會出現嘀嗒聲,但是基本上窗口蟒蛇會打開以查看並保存該圖不夠大,並且擴展它會縮放整個圖像,以便標籤/蜱仍然被切斷。

任何幫助將不勝感激,請不要提及減少字體大小或刪除標籤,因爲這是進入報告,所以這些都是固定的。

謝謝。

回答

3

您可以通過,例如,

ax.dist = 13

觀看 「距離」 設置爲你的陰謀